Page 1 of 1

run method at once each new/save/multiplayer game

Posted: Tue Nov 06, 2018 12:10 pm
by Likos
Hello everyone. I'm trying find working method to run at once my init script, which used game object for parse item prototypes. For multiplayer i'm using script.on_event({defines.event.on_player_joined_game}, myMethod), for new game: script.on_init(myMethod). But i not understand, how i can parse game.item_prototypes for loaded save game in singleplayer. For each game session i'm need run at once this myMethod

Re: run method at once each new/save/multiplayer game

Posted: Wed Nov 07, 2018 8:07 am
by darkfrei
Likos wrote: Tue Nov 06, 2018 12:10 pm But i not understand, how i can parse game.item_prototypes for loaded save game in singleplayer. For each game session i'm need run at once this myMethod
All your parsed info was not changed and can be called from global.

But if something was changed, then you can make new parsing due https://lua-api.factorio.com/latest/Lua ... on_changed
Register a function to be run when mod configuration changes. This is called any time the game version changes, prototypes change, startup mod settings change, and any time mod versions change including adding or removing mods

Re: run method at once each new/save/multiplayer game

Posted: Wed Nov 07, 2018 8:57 am
by bobingabout
Yeah, basically, just save values to the global. variable, it's the only variable that persists through save/load.

Re: run method at once each new/save/multiplayer game

Posted: Wed Nov 07, 2018 4:21 pm
by Optera
bobingabout wrote: Wed Nov 07, 2018 8:57 am Yeah, basically, just save values to the global. variable, it's the only variable that persists through save/load.
Or generate them fresh in on_load.
on_load is called each time someone joins a mp game if i recall correctly.

Re: run method at once each new/save/multiplayer game

Posted: Wed Nov 07, 2018 4:43 pm
by eradicator
Optera wrote: Wed Nov 07, 2018 4:21 pm
bobingabout wrote: Wed Nov 07, 2018 8:57 am Yeah, basically, just save values to the global. variable, it's the only variable that persists through save/load.
Or generate them fresh in on_load.
on_load is called each time someone joins a mp game if i recall correctly.
On_load is called whenever someone loads a savegame. And it is called on that persons machine only. It is not called for new worlds (though one can call the handler manually ofc). Thus the "may not change game state in on_load" restriction.