Hello Corona community,
I have a question about the communication of global variables between modules. Sorry in advance if this question sounds elementary, but could not find an answer with a google search…anyway here it goes!
Suppose with have the following simple code:
-------------- main.lua --------------
globalValue = 1
function increment( )
globalValue = globalValue + 1
print(globalValue)
end
function test( )
local test = require(“test”)
print(test)
end
-------------- test.lua --------------
return globalValue
When I call test( ) for the first time, it prints 1, as expected.
Then we call increment( ). It prints 2.
Now when we call test( ) again, one would assume it’d print 2, but it prints 1 instead!!
Shouldn’t it print 2, since we are creating a fresh copy of the test module every time we call the test( ) function?
This is driving me crazy! I come from a Java background, and emulating OOP in lua has been proving very difficult (and frustrating)…
Please advise me how I can have test( ) print the current value of globalValue.
Thanks in advance!