settings.global is nil

Place to get help with not working mods / modding interface.
Yemto
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sun Aug 28, 2016 1:52 pm
Contact:

settings.global is nil

Post by Yemto »

For about two hours I been attempting to create my second mod, and I'm currently struggling with getting the settings to work. I keep getting an error when it says settings.global is nil, and I have no idea why. I been digging around in other mods I use, and they don't have the same issue.

data.lua

Code: Select all

ores = {
    "infinite-iron-ore",
    "infinite-copper-ore",
    "infinite-coal",
    "infinite-stone"
}

fluids = {
    ["Sulfuric Acid"]   = "sulfuric-acid",
    ["Steam"]           = "steam",
    ["Water"]           = "water",
    ["None"]            = nil
}

for _, ore in ipairs(ores) do
    if settings.global["fluidrequirementoptions-" .. ore .. "-requires"].value ~= nil then
        data.raw.resource[ore].minable.required_fluid = fluids[settings.global["fluidrequirementoptions-" .. ore .. "-requires"].value]
        data.raw.resource[ore].minable.fluid_amount = 10
    end
end
settings.lua

Code: Select all

premade_types = {
    "Sulfuric Acid",
    "Steam",
    "Water",
    "None"
}

data:extend(
{
   {
    type = "string-setting",
    name = "fluidrequirementoptions-infinite-iron-ore-requires",
    order = "a",
    setting_type = "runtime-global",
    default_value = "Sulfuric Acid",
    allowed_values = premade_types
   },{
    type = "string-setting",
    name = "fluidrequirementoptions-infinite-copper-ore-requires",
    order = "b",
    setting_type = "runtime-global",
    default_value = "Sulfuric Acid",
    allowed_values = premade_types
   },{
    type = "string-setting",
    name = "fluidrequirementoptions-infinite-stone-ore-requires",
    order = "c",
    setting_type = "runtime-global",
    default_value = "Water",
    allowed_values = premade_types
   },{
    type = "string-setting",
    name = "fluidrequirementoptions-infinite-coal-ore-requires",
    order = "d",
    setting_type = "runtime-global",
    default_value = "None",
    allowed_values = premade_types
   },
})
Can someone explain to me why settings.global doesn't work? from what I understand, it should.
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: settings.global is nil

Post by Bilka »

Runtime settings (note the name) are available runtime. The data stage is not runtime: http://lua-api.factorio.com/latest/Data-Lifecycle.html

I suggest taking a look at this tutorial instead of relying on other mods that might be doing it wrong: https://wiki.factorio.com/Tutorial:Mod_settings
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Yemto
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sun Aug 28, 2016 1:52 pm
Contact:

Re: settings.global is nil

Post by Yemto »

Bilka wrote:Runtime settings (note the name) are available runtime. The data stage is not runtime: http://lua-api.factorio.com/latest/Data-Lifecycle.html

I suggest taking a look at this tutorial instead of relying on other mods that might be doing it wrong: https://wiki.factorio.com/Tutorial:Mod_settings
Please don't give me links to walls of text, since I don't learn from that. I have been looking at the mod tutorial, and when I attempted to change data.lua to control.lua, I get the error when I try to generate the world, because I don't have access to data.raw there, and can't change the ores that way.
chrisgbk
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Mon Jan 02, 2017 4:31 am
Contact:

Re: settings.global is nil

Post by chrisgbk »

Yemto wrote:
Bilka wrote:Runtime settings (note the name) are available runtime. The data stage is not runtime: http://lua-api.factorio.com/latest/Data-Lifecycle.html

I suggest taking a look at this tutorial instead of relying on other mods that might be doing it wrong: https://wiki.factorio.com/Tutorial:Mod_settings
Please don't give me links to walls of text, since I don't learn from that. I have been looking at the mod tutorial, and when I attempted to change data.lua to control.lua, I get the error when I try to generate the world, because I don't have access to data.raw there, and can't change the ores that way.

In data.lua, the only settings that are available are of type "startup". "runtime-global" and "runtime-per-user" are only available in control.lua. "startup" settings are designed for exactly what you want: controlling prototype creation/modification in data.lua. As the first example of the settings tutorial Usage section shows.
Yemto
Burner Inserter
Burner Inserter
Posts: 16
Joined: Sun Aug 28, 2016 1:52 pm
Contact:

Re: settings.global is nil

Post by Yemto »

chrisgbk wrote:
Yemto wrote:
Bilka wrote:Runtime settings (note the name) are available runtime. The data stage is not runtime: http://lua-api.factorio.com/latest/Data-Lifecycle.html

I suggest taking a look at this tutorial instead of relying on other mods that might be doing it wrong: https://wiki.factorio.com/Tutorial:Mod_settings
Please don't give me links to walls of text, since I don't learn from that. I have been looking at the mod tutorial, and when I attempted to change data.lua to control.lua, I get the error when I try to generate the world, because I don't have access to data.raw there, and can't change the ores that way.

In data.lua, the only settings that are available are of type "startup". "runtime-global" and "runtime-per-user" are only available in control.lua. "startup" settings are designed for exactly what you want: controlling prototype creation/modification in data.lua. As the first example of the settings tutorial Usage section shows.
Thanks, I managed to fix the issues I was having.
Post Reply

Return to “Modding help”