Unexpected game initialization with custom scenario

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1655
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Unexpected game initialization with custom scenario

Post by Pi-C »

I've always thought that only script.on_init() would be triggered whenever a new game was created. This is also supported by the Data lifecycle documentation:
[2] on_init()

This step is only run when starting a new save game or for mods that are new to an existing one. During it, their LuaBootstrap::on_init handler is called to give the mod the chance to set up initial values that it will use for its lifetime. It has full access to the game object and its global table and can change anything about the game state that it deems appropriate.

Note that scenario scripts are treated like mods for this step. [My emphasis.] Also, no other events will be raised for a mod or scenario until it has finished this step.
Based on the sentence I've highlighted in the quotation, I'd also expect this to be the case when a game based on a custom scenario was started.


Yesterday I've created a new game to test one of my mods. I used Creative Mod to research all technologies and placed down some entities. I then went into editor mode, used "Save as scenario", and started a new game based on that scenario. My mod logs the names and arguments of the functions and event handlers that are called. Grepping through the log, I got this sequence of events:

Code: Select all

factorio-current.log:942: Entered event script for on_load
factorio-current.log:1152: Entered event script for on_pre_player_removed
factorio-current.log:1188: Entered event script for on_player_removed
factorio-current.log:1202: Entered event script for on_configuration_changed
factorio-current.log:2428: Entered event script for on_player_joined_game
Found 5 matches for "Entered event script for".
While I may have missed some other events that I don't listen to, the log file really shows no trace of script.on_init() getting called. It seems that either this behavior or the documentation is wrong. Which is it? :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2583
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Unexpected game initialization with custom scenario

Post by FuryoftheStars »

Subscribing so I can follow this, too (and so you know I have :D ).
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics

Post Reply

Return to “Modding discussion”