Using Peach Pellen’s spectacular and clear tutorial, I implimented scene changes with the director class. But when I attempt to go from my menu page (as Peach calls it) to the level1.lua of my game, get this error:
level1.lua:65: attempt to index global ‘backButton’ (a nil value)
I’ve tried the function and the button and the listener in a separate file, so I know those parts are correct. It was suggested that I post the offending code. Hopefully someone knowledgable will have a bit of insomnia this eve and want to tell me what I am doing wrong.
Sure would appreciate some help, I’m going crazy
I apologize in advance for what is probably horrible looking code. I am brand new at this.
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
local background = display.newImage (“farmbg.jpg”)
localGroup:insert(background)
– The images –
local donkey = display.newImage (“donkey.png”)
donkey.x = math.random( 40, 280)
donkey.y = math.random( 40, 440)
localGroup:insert(donkey)
local tail = display.newImage (“tail.png”)
tail.x = math.random( 20, 300)
tail.y = math.random( 20, 460)
localGroup:insert(tail)
– drag and show the back button
function tail:touch( event )
if event.phase == “began” then
display.getCurrentStage():setFocus(event.target)
self.markX = self.x
self.markY = self.y
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y
elseif event.phase == “ended” then
local backButton = display.newImage (“playButton.jpg”)
backButton.x = 160
backButton.y = 440
localGroup:insert(backButton)
end
return true
end
local function pressBack(event)
if event.phase == “ended” then
director:changeScene (“menu”)
end
end
backButton:addEventListener( “touch”, pressBack)
tail:addEventListener( “touch”, tail )
return localGroup
end[/lua] [import]uid: 96383 topic_id: 16669 reply_id: 316669[/import]