I am using director and I would like to make it so if you press a button on one screen, that changes a variable to be used on another screen.
Example code that does not work because I am dumb:
Screen1.lua
[lua]module(…, package.seeall)
– Main function - MUST return a display.newGroup()
color = 0;
function new()
local localGroup = display.newGroup()
–PreStuFZ
– Background
local background = display.newImage(“bg.png”)
localGroup:insert(background)
–Menu
local bt01 = display.newRect(100,150,100,50)
local function bt01t ( event )
if event.phase == “ended” then
director:changeScene(“screen2”,“moveFromLeft”)
end
end
bt01:addEventListener(“touch”,bt01t)
bt01.x = 160
bt01.y = 200
localGroup:insert(bt01)
local bt02 = display.newRect(100,50,100,50)
local function bt02t ( event )
if event.phase == “ended” then
color = 256;
end
end
bt02:addEventListener(“touch”,bt02t)
bt02.x = 180
bt02.y = 270
localGroup:insert(bt02)
– MUST return a display.newGroup()
return localGroup
end[/lua]
Screen2.lua
[lua]module(…, package.seeall)
– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
local background = display.newImage(“bg.png”)
localGroup:insert(background)
local colorex = display.newRect(100,100,100,100)
colorex:setFillColor(color,color,color)
localGroup:insert(colorex)
– MUST return a display.newGroup()
return localGroup
end[/lua]
Thanks! [import]uid: 30000 topic_id: 5919 reply_id: 305919[/import]