Page 1 of 1

How to run code on exit save

Posted: Sat Dec 29, 2018 3:42 am
by ProfoundDisputes
Is there a way to run code to change the player's data before quitting the game? I would like to access the game.players[1].get_inventory(defines.inventory.player_armor) and edit it before quitting.

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 7:29 am
by Bilka
No, because that would not be deterministic.

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 12:36 pm
by Klonan
In Multiplayer there is:

Code: Select all

on_pre_player_left_game
https://lua-api.factorio.com/latest/eve ... _left_game

However this does not work in single player

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 6:27 pm
by darkfrei
Klonan wrote: Sat Dec 29, 2018 12:36 pm In Multiplayer there is:

Code: Select all

on_pre_player_left_game
https://lua-api.factorio.com/latest/eve ... _left_game

However this does not work in single player
Hey, we have solution for multiplayer, but here is no solution for single player while it is not detereministic and makes desync?

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 7:02 pm
by posila
I mean ... what is the point of changing inventory before the player quits singleplayer since the game is literally just about to wipe out the entire game state?

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 7:33 pm
by darkfrei
posila wrote: Sat Dec 29, 2018 7:02 pm I mean ... what is the point of changing inventory before the player quits singleplayer since the game is literally just about to wipe out the entire game state?
It's nice to get greetings on start or statistics about game session on the game ending today.

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 10:03 pm
by ProfoundDisputes
posila wrote: Sat Dec 29, 2018 7:02 pm I mean ... what is the point of changing inventory before the player quits singleplayer since the game is literally just about to wipe out the entire game state?
I was going to do some clean up so that if the player removes the mod it doesn't cause equipment in armor to disappear. My mod mostly changes the equipment in armor dynamically with custom equipement with small modifications. So if the player exited the game I would just swap out the custom equipment with the vanilla equipment. When they load the game swap them back in. That way they won't have missing equipment in armor.

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 10:27 pm
by posila
So you'd need to run script before saving starts and after saving finishes + after load. That's not possible in the current API.

Re: How to run code on exit save

Posted: Sat Dec 29, 2018 10:33 pm
by ProfoundDisputes
posila wrote: Sat Dec 29, 2018 10:27 pm So you'd need to run script before saving starts and after saving finishes + after load. That's not possible in the current API.
*facepalm* Oops. Ya that would be what I need to do. New to modding games here... It would be what you state here.

Re: How to run code on exit save

Posted: Sun Dec 30, 2018 11:18 am
by darkfrei
ProfoundDisputes wrote: Sat Dec 29, 2018 10:03 pm I was going to do some clean up so that if the player removes the mod it doesn't cause equipment in armor to disappear. My mod mostly changes the equipment in armor dynamically with custom equipement with small modifications. So if the player exited the game I would just swap out the custom equipment with the vanilla equipment. When they load the game swap them back in. That way they won't have missing equipment in armor.
Now we have migration script that will be running one when the mod is installed. Here was another suggestion - make uninstall migration script, where you write what must be changed after mod was uninstalled.