How to Access data.raw from control.Lua?

Things that already exist in the current mod API
Post Reply
Twisted6
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Dec 14, 2016 11:17 pm
Contact:

How to Access data.raw from control.Lua?

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Twisted6
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Dec 14, 2016 11:17 pm
Contact:

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

Post 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"

Post Reply

Return to “Already exists”