A global variable I define is not being seen by some of my code, and I don’t know why. Can somebody look at this and tell me what I’m doing wrong… Thank you!
What would be a better way of propagating the data to all the code of my project?
-- main.lua:
display.setStatusBar( display.HiddenStatusBar )
director = require("director")
-- here's the global variable that nobody sees outside of this file
test = "SUPERTEST"
function button\_press( event )
if event.phase == "ended" then
director:changeScene(event.target.scene,"fade")
end
end
local mainGroup = display.newGroup()
local function main()
mainGroup:insert(director.directorView)
director:changeScene("title")
return true
end
main()
-- title.lua
module(..., package.seeall)
local localGroup = display.newGroup()
local title = display.newText( localGroup, "all i'm gonna do is change a 'global'", 0, 0, native.systemFontBold, 24 )
title.scene = "print\_test"
title:addEventListener( "touch", button\_press )
-- here's where I change the global variable
test = "SUPER DUPER TEST"
function new()
return localGroup
end
-- print\_test.lua
module(..., package.seeall)
local localGroup = display.newGroup()
-- this uses the original test value :-(
local title = display.newText( localGroup, "test is "..test, 0, 0, native.systemFontBold, 24 )
function new()
return localGroup
end
[import]uid: 61132 topic_id: 10807 reply_id: 310807[/import]


