Page 1 of 1

[Answered] How to access other mods' settings in settings.lua? (Not possible)

Posted: Mon Jul 01, 2019 4:02 pm
by Schallfalke
Hi all,

I want to read the settings values of other mods (mod A) in my new mod (mod B) settings.lua. In mod B, I want to create options based on a certain value in settings of mod A. Is there a possible way to do this?
In data.lua and control.lua, it is easy. I know the following code will work:

Code: Select all

settings.startup["mod-A-dummy-value-C"].value
But when put in settings.lua, it will report error: "attempt to index global 'settings' (a nil value)", which suggests 'settings' is not created yet at settings stage.

Thanks for your attention,
Schall

Sample code to display what I want to access, if it helps explanation:
Mod A

Code: Select all

--in settings.lua:
data:extend({
    {
        type = "int-setting",
        name = "mod-A-dummy-value-C",
        setting_type = "startup",
        minimum_value = 1,
        default_value = 3
    }
})
Mod B

Code: Select all

--in settings.lua:
local valueC = settings.startup["mod-A-dummy-value-C"].value -- Does not work!
for i=1,valueC do
    -- Do something fancy about options...
end

Re: How to access other mods' settings in settings.lua?

Posted: Mon Jul 01, 2019 4:16 pm
by Choumiko
Just like you change things in the data stage, through data.raw

Code: Select all

data.raw["bool-setting"]["something_sth"].default_value = false
settings stage is basically data stage, except there are only settings available

Re: How to access other mods' settings in settings.lua?

Posted: Mon Jul 01, 2019 4:40 pm
by eradicator
Choumiko wrote: Mon Jul 01, 2019 4:16 pm Just like you change things in the data stage, through data.raw

Code: Select all

data.raw["bool-setting"]["something_sth"].default_value = false
settings stage is basically data stage, except there are only settings available
Slightly incorrect. In setting stage there are only settings prototypes available. Setting stage has no read access to *any* setting values. And data stage only has read access to startup setting values.

TL;DR: You can not base new settings on the *actual value* of any other setting. Only on the given defaults and value ranges.

Re: How to access other mods' settings in settings.lua?

Posted: Tue Jul 02, 2019 10:56 am
by Schallfalke
Thanks for the answer.
So it is still not supported by the API, no real interactions of settings between mods...

Re: How to access other mods' settings in settings.lua?

Posted: Tue Jul 02, 2019 11:09 am
by eradicator
Schallfalke wrote: Tue Jul 02, 2019 10:56 am Thanks for the answer.
So it is still not supported by the API, no real interactions of settings between mods...
Well think about it. Settings are created based on the settings-phase prototypes. You're trying to read a setting before it is defined. Nothing however prevents you from reading other mods settings in data/control.