Loading data from script-output

Place to get help with not working mods / modding interface.
DeathTech
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Apr 28, 2016 9:23 am
Contact:

Loading data from script-output

Post 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.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Loading data from script-output

Post 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.
quick links: log file | graphical issues | wiki
DeathTech
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Apr 28, 2016 9:23 am
Contact:

Re: Loading data from script-output

Post by DeathTech »

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.
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.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Loading data from script-output

Post by prg »

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!
DeathTech
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Apr 28, 2016 9:23 am
Contact:

Re: Loading data from script-output

Post 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.
User avatar
Lutra
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Fri Apr 01, 2016 9:22 pm
Contact:

Re: Loading data from script-output

Post 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?
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Loading data from script-output

Post 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 :)
Post Reply

Return to “Modding help”