C. P. Wagner
C. P. Wagner

Reputation: 561

Corona SDK Global Table not visible in Module

I am having trouble referencing a global table in the Corona SDK.

--main.lua
_G.settings = 
{
    WIDTH = display.contentWidth,
    HEIGHT = display.contentHeight,
}
print(_G.settings.WIDTH)
=> 320



--module1.lua
print(_G.settings.WIDTH)
=> nil

I'm not sure why module1.lua is nil while it works in main.lua is going on.

Upvotes: 0

Views: 35

Answers (1)

ldurniat
ldurniat

Reputation: 1702

I tested your code and it works for me. I can not reproduce your error.

NOTICE:

If you create global variable in Lua for example myVariable you have access to it by global table _G

_G.myVariable

or by its name

myVariable

So may be you have changed variable settings somewhere (in main.lua or module1.lua)?

I also recommended you read about global variables in Lua.

Upvotes: 0

Related Questions