Jump to content

GetModConfigData not working?


Recommended Posts

Does anyone have a guide on how this function works?  I can't seem to find one anywhere.

>>>I added config data to my mod main file:

"configuration_options = {
{
    name = "speedoption",  --How to reference this configuration in other file locations.
    label = "Temperature's affect on speed",  --What appears on the configuration options menu.
    hover = "Non-linear:  Low temperature benefits are more reliable, and high temperature debuff are easier to recover from. Linear:  More predicatable.",
    options = 
        {
            {description = "Non-linear", data = 1},
            {description = "Linear", data = 2},
        },
        default = 1,
    },

}"

>>>and then tried calling it in another file:

if GetModConfigData("speedoption") == 1 then
        inst.components.locomotor.walkspeed =  (55/(0.0035*inst.components.temperature.current^2+10)+1)
        inst.components.locomotor.runspeed = (55/(0.0035*inst.components.temperature.current^2+10)+2)

else
        inst.components.locomotor.walkspeed =  -0.04211*inst.components.temperature.current+6.3
        inst.components.locomotor.runspeed = -0.04211*inst.components.temperature.current+7.3
end

>>This crashes my mod.  I'm guessing I need to port in the configuration values, but can't find a mod where they do this.  Does anyone know how configuration values are called?  When I comment out the configuration code in the second file, the mod works perfectly, but when called, the game runs for a few seconds, but crashes after a second or two.

Edited by FurryEskimo
Link to comment
Share on other sites

the quotes were just my attempt to differentiate it from my descriptions, my mistake.
I found a few mods that use configurable options, but it’s proven to be a little, complicated.  It seems like the options are listed in the modinfo file (or mod ain, I forget) and then they import the character’s file or other relevant files into that first file.  I thought it worked the other way around.  It’s going to take me a little longer than I expected to wrap my head around this, but it’s probably easier than it looks to me now.

Link to comment
Share on other sites

When I first started making this mod it would crash and display an error report, usually a problem with syntax, but it hasn’t been doing that lately, instead It’s crashing once the server is running (when the character’s speed is set based on configurable data), and there is no error message displayed.  If it’s producing an error report and storing it somewhere, I’m not aware of it.
as for importing the information, my software engineer brother suggested something like:

import .../“scripts/probabs/FileName”

This would go in the file that needs to reference the settings, allowing GetModConfigData to work, but so far I haven’t been able to get it to work, and can’t find an example of such code in any mods.

Edited by FurryEskimo
Link to comment
Share on other sites

Ok, I had some time to go back in and look around at the code.  I'm looking at the code for "Epic Health Bar" https://steamcommunity.com/sharedfiles/filedetails/?id=1207269058&searchtext=epic+health+bar
In their modmain.lua file there's a line of code reading:
modimport "scripts/tools/waffles"
table.insert(Waffles.GetPath(env, "Assets"), Asset("ATLAS", "images/hud/epichealthbar.xml"))

Waffles.Parallel(require "components/health_replica", "_ctor", function(self, inst)
    if inst:HasTag("epic") then
        AddEpicHealthbarNetvars(inst)
    end
end)

TUNING.EPICHEALTHBAR =
{
    COMBAT_TIMEOUT = config.timeout or 10,
    TRIGGER_DIST = config.distance or 20,
    THEMES =
    {
        DEFAULT =
        {        
            GENERIC =            { 0.90, 0.05, 0.05 },
            DEERCLOPS =            { 0.31, 0.45, 0.62 },
            BEARGER =            { 0.07, 0.07, 0.07 },
            MOOSE =                { 0.31, 0.18, 0.31 },
            DRAGONFLY =            { 0.20, 0.00, 0.00 },                                               
            ANTLION =            { 0.80, 0.47, 0.13 },
            TOADSTOOL =            { 0.18, 0.03, 0.33 },
            TOADSTOOL_DARK =    { 0.91, 0.85, 0.24 },
            BEEQUEEN =            { 0.80, 0.47, 0.13 },
            KLAUS =                { 0.90, 0.05, 0.05 },                                               
            MINOTAUR =            { 0.55, 0.52, 0.49 },
            STALKER =            { 0.28, 0.24, 0.55 },
            STALKER_ATRIUM =    { 0.90, 0.05, 0.05 },
            STALKER_FOREST =    { 0.34, 0.49, 0.23 },                                               
            SPIDERQUEEN =        { 0.93, 0.66, 0.72 },
            LEIF =                { 0.14, 0.36, 0.25 },
            LEIF_SPARSE =        { 0.14, 0.36, 0.25 },
            SHADOW_ROOK =        { 0.07, 0.07, 0.07 },
            SHADOW_KNIGHT =        { 0.07, 0.07, 0.07 },
            SHADOW_BISHOP =        { 0.07, 0.07, 0.07 },
            MALBATROSS =        { 68 / 255, 90 / 255, 137 / 255 },
            CRABKING =            { 239 / 255, 237 / 255, 140 / 255 },
        },                                         
                                            
        WINTERS_FEAST =                            
        {                                          
            DEERCLOPS =            { 0.69, 0.23, 0.21 },
            BEARGER =            { 0.85, 0.87, 0.69 },
            MOOSE =                { 0.34, 0.23, 0.18 },
            DRAGONFLY =            { 0.90, 0.71, 0.15 },
        },
    },
}

>>>Mofinfo.lua says:
configuration_options =
{    
    {    
        name = "timeout",
        label = "Combat Timeout",
        hover = "If the boss has no interest in players for this\namount of time, the bar disappears.",
        options = options_timeout,
        default = 10,
    },
    
    {
        name = "distance",
        label = "Trigger Distance",
        hover = "Maximum distance from which bosses can trigger the bar.\nExceeding the distance makes the bar disappear.",
        options = options_distance,
        default = 20,
    },
}

>>>While the item in question says:
 

config = {}

local _config, temp_options = KnownModIndex:GetModConfigurationOptions_Internal(modname)
if type(_config) == "table" then
    if temp_options then
        for k, v in pairs(_config) do
            if k ~= "" then
                config[k] = v
            end
        end
    else
        for i, v in pairs(_config) do
            if v.name ~= "" then
                if v.saved ~= nil then
                    config[v.name] = v.saved
                else
                    config[v.name] = v.default
                end
            end
        end
    end
end

>>>From what I can tell, configuration options are listed in modinfo.lua, something happens in modmain.... and then waffles.lua somehow calls on that data.  Waffles.lua does have a lot of code I don't yet understand, including "_G = GLOBAL", but I'm not sure how these files are sharing variables..

Edited by FurryEskimo
Link to comment
Share on other sites

You mean sharing data from the config to the modmain? what error did you recieve with your current/fixed version that you assume the config data is not there?

Because you can access your config data from the modinfo to the modmain using "GetModConfigData". If you need your modinfo data in a prefab file or somewhere else beyond the modmain, then you can define a gloabal variable in the modmain where you save the configdata in.

i think i dont understand at what point your problem is, can you maybe share your current version/files and log error message?

Link to comment
Share on other sites

I might be able to share it soon, but right now it’s bloated with outdated versions of the code and way too many comments.

As for global variables, I was told they don’t extend beyond a single file.  In my modinfo file (I think) I offered configurable options, but need to reference those selections in the character’s file.  It sounds like “GetModConfigData” only works in mainmod.lua, but a global variable can be referenced?  I’ve seen global variables referenced in a few spots, but usually it’s something like “_G = Global” which currently makes no sense to me.

Link to comment
Share on other sites

Global variables can be called anywhere in the game. When in your modmain you need to specify if a variable is global before calling it, which is why there it might say something like GLOBAL.TUNING.WHATEVER whereas in every other file in the mod it's just TUNING.WHATEVER
I'm not completely sure why the modmain is different from everywhere else in the mod like that, but it is.
Local variables can only be called inside the function they're defined in (or if defined outside any functions, within the file they're defined in)
So what you should do in your modmain to define the variable to be used elsewhere is

GLOBAL.variablename = GetModConfigData("speedoption")

Then in whatever file you need just do

if variablename == whatyouwant then
	--do the thing
end




From what I understand you can have a variable that is a mix between global and local, in that it can be called anywhere *inside your mod specifically* but won't be callable elsewhere. In the instance of calling mod configuration, this might be a better idea than globals for compatibility reasons. I'm not totally sure but I think all you do to define it is put env. before it, like this

env.variablename = GetModConfigData("speedoption")

Keep in mind I haven't tried using that env. yet so if it doesn't work, I can't help you. It might be worth a shot though.



EDIT:
The reason people do local _G = GLOBAL in their mods is because it's shorter and thus quicker to type, and also because _G is how global variables are normally referenced in lua. For some reason Klei made it so you have to call GLOBAL instead of _G, and so many people will put local _G = GLOBAL at the top of their mod.

Edited by Eusong
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...