Page 1 of 1

Data.lua in scenarios

Posted: Sun Oct 16, 2016 1:46 pm
by SamSam
Even if it only allowed GUI styles or technologies and disallowed entities, having data.lua functional in scenarios would be quite useful in some cases. Maybe you want to restrict this to mods only, but it seems to me like adding limitations is usually not a good thing. Maybe there's a reason due to the way scenarios are loaded, in which case i understand if it is too complex or bad for performance to change the behaviour.
Thank you :D

Re: Data.lua in scenarios

Posted: Sun Oct 16, 2016 7:47 pm
by ssilk
Hm. I think you need to understand, that this is not possible yet.

The right way to do this is to define as many different GUI's as you need and exchange them "on the fly". :)

Re: Data.lua in scenarios

Posted: Sun Oct 16, 2016 9:02 pm
by SamSam
Is there a reason that this isn't possible? It works like this in a mod, and I'm just requesting that this behaviour is extended. Maybe I'm missing something here :?:

Re: Data.lua in scenarios

Posted: Sun Oct 16, 2016 10:44 pm
by Rseding91
SamSam wrote:Is there a reason that this isn't possible? It works like this in a mod, and I'm just requesting that this behaviour is extended. Maybe I'm missing something here :?:
Because all mods must be the same when joining a game. Because scenarios don't have prototype data they can be loaded runtime and as such don't require you install anything special to join a server with a custom scenario running.

Re: Data.lua in scenarios

Posted: Mon Oct 17, 2016 12:05 am
by SamSam
I think I get it, a mod's data.lua is run when the game is restarted?

Re: Data.lua in scenarios

Posted: Mon Oct 17, 2016 1:47 pm
by daniel34
SamSam wrote:I think I get it, a mod's data.lua is run when the game is restarted?
Yes. data.lua is only run when the game (the Factorio application/server) starts, during the mod loading phase. control.lua is run everytime you load a savegame or start a new game.

See also this: https://wiki.factorio.com/index.php?tit ... Flifetimes
When Factorio starts up, all data-related scripts are run in a shared lua interpreter to populate and modify a global variable named data which is used to define prototypes. First all mods' data.lua are called, then all mods' data-updates.lua, then finally all mods' data-final-fixes.lua. Note that this means there is no game session running (i.e. no global or game state) at the time data-related scripts are executed, and any changes to lua module state will be discarded, preventing them from affecting control.lua.
[...]
control.lua is used by mods to directly interact with a game session while the game is being played; it has access to game state and to global (see below). All mods' control.lua are sandboxed from each other by running them in separate interpreters that exist for the duration of a game session. Because control.lua is reloaded and re-run every time a new game session is started, you don't need to completely restart Factorio to notice changes made to control.lua; simply saving/loading or starting a new game is sufficient.

Re: Data.lua in scenarios

Posted: Mon Oct 17, 2016 5:40 pm
by ssilk
It's a repeated wish, that modders don't need to restart the whole game, if they just change small graphics.

Added to viewtopic.php?f=80&t=27805 Suggestion around Game-Internal Mods-Handling/Mods-Management