So when my game starts my eventListener starts and i need to tap the screen. But if i tap the screen before the object spawns then i get a nil error. How would i check if the object is there or not? Here’s original code and then what i tried to do.
Original –
local object = {} local objectRemove = 1 local function touchy(event) local objectWidth = object[objectCheck].width if event.phase == "began" then display.remove( object[objectRemove] ) objectRemove = objectRemove + 1 else composer.gotoScene("gameOver") end end end end Runtime:addEventListener( "touch", touchy )
What I tried –
local object = {} local objectRemove = 1 local function touchy(event) if object ~= nil then else local objectWidth = object[objectCheck].width if event.phase == "began" then display.remove( object[objectRemove] ) objectRemove = objectRemove + 1 else composer.gotoScene("gameOver") end end end end Runtime:addEventListener( "touch", touchy )
Thanks!