Attempt to index local 'event' (a nil value) error

Guys sorry to keep coming back to this, Ive had a go at both suggestions but they don’t seem to work 

Both have upValue errors. For cyberparkstudios suggestion I get the up value for ‘pick1’ and ‘pick2’ event though I have forward declared them at the top of my code. 

@hasty, the firstObj and secondObj get up values errors too. 

I’ve add to CPSs example a little and tested, and it definitely works:

local pick1, pick2 local counter = 0 function whichTap(self, event) if event.phase == "ended" then counter = counter + 1 if counter == 1 then pick1 = event.target else pick2 = event.target counter = 0 local firstX = pick1.x local firstY = pick1.y local secondX = pick2.x local secondY = pick2.y transition.to(pick2, {time = 1500, x = firstX, y = firstY}) transition.to(pick1, {time = 1500, x = secondX, y = secondY}) end end return true end local x = display.newRect( 100, 160, 50, 50) x:setFillColor(1, 0, 0) local y = display.newRect( 220, 160, 50, 50) y:setFillColor(0, 0, 1) x.touch = whichTap y.touch = whichTap x:addEventListener("touch", x) y:addEventListener("touch", y)

I know I’ve gotten upvalue errors like this before despite having forward-declared, and endured much frustration over it, only for it to be something simple. Alas, I can’t recall any examples.

haha I know what you mean about them errors. Funny thing is I changed something with the firstObj and secondObj code above and, what didn’t work before, all of a sudden works perfectly now. Strange but oh well. I will try CPS’ code again too. Thanks again, learnt a lot there.