Is there a way to load a file from script-output into our control.lua?
Or in another way, how do we store data for mods?
I would like to know how to store / retrieve data.
Loading data from script-output
Re: Loading data from script-output
No, you can't load/read data from script-output.
Use the global table instead: https://wiki.factorio.com/index.php?tit ... cle#global
Everything stored there will be saved in the savegame and is still there after loading the save.
Use the global table instead: https://wiki.factorio.com/index.php?tit ... cle#global
Everything stored there will be saved in the savegame and is still there after loading the save.
Re: Loading data from script-output
I though as much, though people keep telling to "use globals" and then refference a page that tells you nothing on how to use them.daniel34 wrote:No, you can't load/read data from script-output.
Use the global table instead: https://wiki.factorio.com/index.php?tit ... cle#global
Everything stored there will be saved in the savegame and is still there after loading the save.
What do I write to save into globals?
What do I write to load from globals?
Its not explained on the page.
Re: Loading data from script-output
You just do global.my_variable = my_value and global.my_variable will still have my_value after a save/load.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Loading data from script-output
Well that worked, I think.prg wrote:You just do global.my_variable = my_value and global.my_variable will still have my_value after a save/load.
Don't know why it didn't work before when I tried that method. But it works now. Thanks guys.
Re: Loading data from script-output
similar topic: is it possible to declare an array in lib.lua, then use the on_init event to copy it to an array that is usable/editable in control.lua then saved in global but not changed in lib so that it can be used for multiple games?
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Re: Loading data from script-output
Lutra wrote:similar topic: is it possible to declare an array in lib.lua, then use the on_init event to copy it to an array that is usable/editable in control.lua then saved in global but not changed in lib so that it can be used for multiple games?

lib.lua
Code: Select all
return {somInteger = 1, something = {foo={true,false}, bar="baz"}
Code: Select all
script.on_init()
global.data = require 'lib.lua'
end
--somewhere
global.data.someInteger = 2
