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

Place to get help with not working mods / modding interface.
Post Reply
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

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

Post 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
Last edited by Schallfalke on Tue Jul 02, 2019 10:58 am, edited 1 time in total.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

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

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.


User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”