I’ve been following this tutorial as its the exact mechanic I am looking for, but I seem to be getting an event = nil value error. I can’t figure out why this is happening.
I have 3 objects with listeners on them which go through the logical if statement to determine if its a 1st or 2nd tap, but the error comes when the whichTap function redirects.
castle = display.newRect(0,0,106,60) -- RED castle.anchorX = 0.0 castle.anchorY = 0.0 castle.x = 0 castle.y = display.contentHeight - 15 castle.name = "redCastle" castle:setFillColor(228/255,59/255,91/255) physics.addBody( castle, {isSensor = true} ) castle.touch = whichTap castle:addEventListener("touch") baseGroup:insert(castle) castle2 = display.newRect(0,0,106,60) castle2.anchorX = 0.0 castle2.anchorY = 0.0 castle2.x = castle.width castle2.y = display.contentHeight - 15 castle2.name = "greenCastle" castle2:setFillColor(170/255,220/255,84/255) --castle2.alpha = 0.1 physics.addBody( castle2, {isSensor = true} ) castle2.touch = whichTap castle2:addEventListener("touch") baseGroup:insert(castle2) castle3 = display.newRect(0,0,106,60) castle3.anchorX = 0.0 castle3.anchorY = 0.0 castle3.x = castle2.width+ 106 --212 castle3.y = display.contentHeight - 15 castle3.name = "blueCastle" castle3:setFillColor(103/255,211/255,248/255,248) physics.addBody( castle3, {isSensor = true} ) castle3.touch = whichTap castle3:addEventListener("touch") baseGroup:insert(castle3)
They direct to whichTap function
function firstTapEventListener(event) firstX = event.target.x firstY = event.target.y firstName = event.target.name end function secondTapEventListener(event) secondX = event.target.x secondY = event.target.y secondName = event.target.name transition.to(secondName, {time = 1500, x = firstX, y = firstY}) transition.to(firstName, {time = 1500, x = secondX, y = secondY}) end function whichTap(event) if counter == 1 then firstTapEventListener() else secondTapEventListener() end end