Jump to content

Defining a Variable in Modmain


Recommended Posts

I have these line in Modmain.lua

================
W101_FLOAT = 0

if GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) or GLOBAL.IsDLCEnabled(GLOBAL.PORKLAND_DLC) then
     W101_FLOAT=1
end
================
Then In one of several prefabs
================
if W101_FLOAT ==1 then ....
================
However, when the prefab is loaded, the game crashes with the error that the variable is not defined

My knowledge of Lua is limited, and I am sure I am missing something iimportant in the way that Lua works..

Any help would be appreciated.

Link to comment
Share on other sites

This would probably be both strict.lua being mean and the scope of the variable.

In modmain:

GLOBAL.global("W101_FLOAT") -- For strict.lua to be happy, declares this as a global

GLOBAL.W101_FLOAT = 1

Prefab:

if _G.W101_FLOAT == 1 then -- _G should be defined here, if not then use GLOBAL.  This forces the global context scope

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...