Page 1 of 1

How to Access data.raw from control.Lua?

Posted: Tue May 16, 2017 6:27 pm
by Twisted6
I realised data.lua is loaded before settings.lua so instead is there a way to modify data from control.lua? I've tried but get a nil value error on "data" in eg "data.raw.ammo"

As an example here is some code that doesn't work.

Code: Select all

for i, ammo in pairs(data.raw.ammo) do
  ammo.magazine_size = settings.global["magazine_size"].value
end

Re: How to Access data.raw from control.Lua?

Posted: Tue May 16, 2017 6:31 pm
by Rseding91
If you want to change prototype values with settings you need to use the startup setting type.

Global settings can be changed runtime which means they can't be used to build prototypes since prototypes can't be changed runtime.

Re: How to Access data.raw from control.Lua?

Posted: Tue May 16, 2017 7:57 pm
by Twisted6
Rseding91 wrote:If you want to change prototype values with settings you need to use the startup setting type.

Global settings can be changed runtime which means they can't be used to build prototypes since prototypes can't be changed runtime.
Much appreciated.

For anyone also looking for the solution, in settings.lua change

Code: Select all

setting_type = "runtime-global"
to

Code: Select all

setting_type = "startup"