Scenario locale is loaded after scenario control.lua runs

This subforum contains all the issues which we already resolved.
chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Scenario locale is loaded after scenario control.lua runs

Post by chrisgbk »

This didn't matter before, but now that log() and print() support localized strings, it seems a bit silly that the scenario locale is unavailable to the scenario until run-time. Localized strings during loading would be very nice in some cases, like debugging.

Attached is a mod that contains a scenario with an embedded locale; scenario code makes two identical calls to log{...}, one inside an event, the other outside. One succeeds, one fails.

Code: Select all

  15.398 Script @.../Factorio/temp/currently-playing/control.lua:1: Unknown key: "scenario-test"
...
  15.424 Verbose AppManager.cpp:509: Time to create game: 0.733736 seconds.
  15.425 Script @.../Factorio/temp/currently-playing/control.lua:4: test
Expected behaviour is that both calls would work and print localized text.
Attachments
scenario-locale_1.0.0.zip
(1.84 KiB) Downloaded 70 times

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by eradicator »

If two scenarios can have different locales for the same key it's impossible to know which one you want though?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13974
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by Rseding91 »

Script locale is loaded before control.lua is run for that mod.

The game loads the scenario locale, then the scenario script. Then each mod in series in that same order.

If your scenario script requires some locale then it should include it and not rely on another mod.
If you want to get ahold of me I'm almost always on Discord.

chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by chrisgbk »

Rseding91 wrote:Script locale is loaded before control.lua is run for that mod.

The game loads the scenario locale, then the scenario script. Then each mod in series in that same order.

If your scenario script requires some locale then it should include it and not rely on another mod.
The scenario does include the locale - that's why this is being reported. Check /scenarios/Locale-Test/locale/en/test.cfg

There is no reliance on another mod here - the scenario itself already contains the locale. Not to be confused with a mod locale, which is at the same level as info.json, which does get loaded first if it exists. If the locale is moved out of the scenario to the mod level, then it works as expected, but only if the mod is installed.

As the point of this particular scenario is that it's not game-state altering(server-side soft mod), and thus it's not a required mod, means clients aren't expected, nor required, to have the mod installed, which is why the locale is in the scenario: so it gets embedded in the save, and all connecting clients have access to it. Except they don't have access to it until Factorio starts raising events.

Summary:
A scenario embedded in a mod has access to that mods locale at all times, including during loading of control.lua
A scenario that contains a locale internally only has access to that locale inside events that Factorio raises
A scenario that contains a locale internally cannot access that locale during loading of control.lua

eradicator wrote:If two scenarios can have different locales for the same key it's impossible to know which one you want though?
Scenario locales are embedded in the save files, and pulled from the scenario directory you create the scenario from. When you create a scenario, or load a saved scenario, it's obvious which one is appropriate to load, because either it's in the save file, or it's in the scenario directory. The point of this was, when you specifically load a scenario, that has an embedded locale, it's not available to the running scenario code until Factorio starts raising events.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by eradicator »

Rseding91 wrote:The game loads the scenario locale, then the scenario script. Then each mod in series in that same order.
chrisgbk wrote:The point of this was, when you specifically load a scenario, that has an embedded locale, it's not available to the running scenario code until Factorio starts raising events.
Either of you two is wrong, cos that's a contradiction right there :P.

chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by chrisgbk »

eradicator wrote:
Rseding91 wrote:The game loads the scenario locale, then the scenario script. Then each mod in series in that same order.
chrisgbk wrote:The point of this was, when you specifically load a scenario, that has an embedded locale, it's not available to the running scenario code until Factorio starts raising events.
Either of you two is wrong, cos that's a contradiction right there :P.
Yes, it is. There's an attached scenario in the first post that has the code:

Code: Select all

log{...}

script.on_event(...,function(e)
    log{...}
end)
I would expect that either both of those would print the translated key, or both would print the key is unknown, but the observed behavior is half and half - one prints unknown the other prints translated. This is also the behavior if the scenario is extracted and manually installed.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13974
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Scenario locale is loaded after scenario control.lua runs

Post by Rseding91 »

I looked into it more and the locale is being loaded before the script but because the game isn't fully loaded yet the game logging logic won't use the locale loaded for the being-loaded map while it's still being loaded.

It's fixed for 0.17.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Resolved Problems and Bugs”