Jump to content

Is it possible to get access to game files from modinfo?


Cyde042

Recommended Posts

I want to dynamically fill the configuration option table based on my own criteria, so I want to get access to prefab0002 (prefab list for Shipwrecked). But the thing is, I can't even index Global... Any ideas?

Here's the relevant part.

Spoiler

configuration_options = {}

for k,v in pairs(GLOBAL.package.loaded.prefab0002) do --says can't index GLOBAL, but without it, it says "requires Global to index Package"
    if v.components.inventoryitem then
        table.insert(configuration_options, 1)
        print("Adding " .. v)
    end
end

Also, how the hell do I add a nested list with a function to a list?

Spoiler

configuration_options = {}

for k,v in pairs(GLOBAL.package.loaded.prefab0002) do
    if v.components.inventoryitem then
        table.insert(configuration_options,

           {
            name = v,
            label = GLOBAL.STRINGS.NAMES.PREFAB,
            options = stackSize,
            default = function(v) if v.components.stackable then return v.components.stackable.maxsize else return 1 end, --it doesn't like the function for some reason, says unexpected symbol near ','
            })
        print("Adding " .. v)
    end
end

 

Link to comment
Share on other sites

modinfo.lua has basically no access to the global environment or any of its variables and functions. You can access your mod's modinfo from modmain (just use MODCONFIG), though there's a comment warning about modifying it in-game, so it might not work entirely.

Link to comment
Share on other sites

20 minutes ago, Mobbstar said:

modinfo.lua has basically no access to the global environment or any of its variables and functions. You can access your mod's modinfo from modmain (just use MODCONFIG), though there's a comment warning about modifying it in-game, so it might not work entirely.

You mean GetModConfigData? But then the issue is that it will need a prebuilt configuration_options table.

What I want to do is create a dynamic one, that builds itself from another table. Would it be possible to access a file in the mod folder maybe? Then I would simply need to copy-paste the list in my mod directory.

Link to comment
Share on other sites

55 minutes ago, Cyde042 said:

What I want to do is create a dynamic one, that builds itself from another table. Would it be possible to access a file in the mod folder maybe? Then I would simply need to copy-paste the list in my mod directory.

MODCONFIG is the configuration_options table's name in modmain.lua: table.insert(MODCONFIG, {name = "sample option"})

Link to comment
Share on other sites

17 hours ago, Mobbstar said:

MODCONFIG is the configuration_options table's name in modmain.lua: table.insert(MODCONFIG, {name = "sample option"})

Doesn't work.

For some reason, I can't access the components of the prefab list. Would you know what to do about that?

Spoiler

for k,v in pairs(GLOBAL.PREFABFILES) do
        if v.components then --says "can't index"
            if v.components.inventoryitem and not v.components.tool and not v == "heatrock" then
                table.insert(MODCONFIG,
                    {
                    name = v,
                    label = GLOBAL.STRINGSS.PREFAB,
                    options = stackSize,
                    default = function(v) if v.components.stackable then return v.components.stackable.maxsize else return 1 end end,
                    })
                print(v)
            end
        end
end

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...