0
votes

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.

1

1 Answers

0
votes

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.