run method at once each new/save/multiplayer game

Place to get help with not working mods / modding interface.
User avatar
Likos
Burner Inserter
Burner Inserter
Posts: 11
Joined: Tue Mar 21, 2017 4:00 pm
Contact:

run method at once each new/save/multiplayer game

Post 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
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

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

Post 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
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post by bobingabout »

Yeah, basically, just save values to the global. variable, it's the only variable that persists through save/load.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

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

Post 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.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
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.
Post Reply

Return to “Modding help”