script.on_init() contradicting documentation

Place to get help with not working mods / modding interface.
Mathematics7
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun May 14, 2017 9:09 am
Contact:

script.on_init() contradicting documentation

Post by Mathematics7 »

It's not clear to me when functions regisered by script.on_init() are called.
According to the factorio lua api: LuaBootstrap:
on_init(f)
Register a callback to be run on mod init. This is called once when a new save game is created or once when a save file is loaded that previously didn't contain the mod. This is always called before other event handlers and is meant for setting up initial values that a mod will use for its lifetime.
Parameters
  • f :: function(): The function to call. Passing nil will unregister the handler.
But according to the factorio lua api: data-lifecycle:
Using the mod order each mod is setup:
  • When creating a new game, script.on_init() will be called on each mod that has a control.lua file.
    When loading a save game and the mod existed in that save game script.on_load() is called.
    When loading a save game and the mod did not exist in that save game script.on_init() is called.
The difference is one word (new game vs new save game), but it's quite a difference. Can anyone please tell me which one is correct?
Last edited by Mathematics7 on Sun Aug 27, 2017 5:55 pm, edited 1 time in total.
User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: script.on_init() contradicting documentation

Post by Optera »

I don't see what the difference between new game and new save game should be.
Both mean when the world is initially created.

If anything new save game is phrased wrong as it can be misinterpreted as when you create a new save file.
Mathematics7
Burner Inserter
Burner Inserter
Posts: 8
Joined: Sun May 14, 2017 9:09 am
Contact:

Re: script.on_init() contradicting documentation

Post by Mathematics7 »

Oke, thank you. I misinterpreded 'new save game' as creating a saved game.
Post Reply

Return to “Modding help”