run method at once each new/save/multiplayer game
run method at once each new/save/multiplayer game
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
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
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: run method at once each new/save/multiplayer game
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
Or generate them fresh in on_load.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.
on_load is called each time someone joins a mp game if i recall correctly.
My Mods: mods.factorio.com
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: run method at once each new/save/multiplayer game
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.Optera wrote: ↑Wed Nov 07, 2018 4:21 pmOr generate them fresh in on_load.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.
on_load is called each time someone joins a mp game if i recall correctly.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.