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]