Global Vars with Director

I am trying to save the game state to a file, but my globals aren’t updating in the event listener. Also I am using the Director Class.
[lua]–main.lua
money = true
function Runtime:system( event )
if event.type == “applicationExit” then
local path = system.pathForFile( “data.txt”, system.DocumentsDirectory )
local file = io.open( path, “w+b” )
if money then m = else m = 0 end
file:write( “Has Money”…", "…v)
io.close( file )
end
end

local function startIt()
director:changeScene(“nextPlace”)
Runtime:addEventListener( “system”, Runtime )
end[/lua]

It acts as if the money in main.lua is different from the money in nextPlace.lua.

[lua]–nextPlace.lua
module( …, package.seeall )
local localgroup = display.newGroup()
function showPong()
local img = display.newImage(“pong.png”)
localgroup:insert(img)
function img:tap( event )
money = false
end
img:addEventListener( “tap”, img )
end
function new()
showPong()
return localGroup
end[/lua]
What am I doing wrong, they are spelled the same and are supposed to be Global. [import]uid: 54716 topic_id: 10987 reply_id: 310987[/import]

I believe in order to make a variable truly global it must be declared with an underscore and uppercase letter such as:

\_M = true

Otherwise it is only global within the module it was declared in. You should still cache your globals in a local variable for use within a module for better performance. [import]uid: 27965 topic_id: 10987 reply_id: 39971[/import]

You could also use
main.money
inside of your nextPlace.lua file to refer to that variable [import]uid: 22392 topic_id: 10987 reply_id: 39978[/import]

Thanks all.I can only read money while in other files. Is it safe to continue or should I switch to one of your methods just to be safe? Also, a nice little work around I found is creating a function which can be called elsewhere like:
[lua]–main.lua
money = false
function toggleMoney()
money = not money
end[/lua]
[import]uid: 54716 topic_id: 10987 reply_id: 39987[/import]