Page 1 of 1
Loading data from script-output
Posted: Thu May 05, 2016 3:33 pm
by DeathTech
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.
Re: Loading data from script-output
Posted: Thu May 05, 2016 3:47 pm
by daniel34
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.
Re: Loading data from script-output
Posted: Thu May 05, 2016 3:50 pm
by DeathTech
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.
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
Posted: Thu May 05, 2016 3:54 pm
by prg
You just do global.my_variable = my_value and global.my_variable will still have my_value after a save/load.
Re: Loading data from script-output
Posted: Thu May 05, 2016 4:04 pm
by DeathTech
prg wrote:You just do global.my_variable = my_value and global.my_variable will still have my_value after a save/load.
Well that worked, I think.
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
Posted: Sun May 08, 2016 4:29 pm
by Lutra
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?
Re: Loading data from script-output
Posted: Sun May 08, 2016 5:02 pm
by Choumiko
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"}
control.lua
Code: Select all
script.on_init()
global.data = require 'lib.lua'
end
--somewhere
global.data.someInteger = 2
That should work, if that's what you where asking
