I think it is happening because of ‘removeEventListener’ line
How I can fix it? Maybe I need some delay before removing listener?
local function pickUpAntiAlien0( event )
if event.phase == "began" then
print("touch")
antiAlien.removeEventListener("touch", pickUpAntiAlien0)
if hero.weapon1 == "empty" then
print("1 slot empty")
hero.weapon1 = "anti-alien"
end
end
end
local function pickUpAntiAlien( event )
if event.phase == "began" then
print("start")
antiAlien:addEventListener("touch", pickUpAntiAlien0)
elseif event.phase == "ended" then
print("end")
antiAlien:removeEventListener("touch", pickUpAntiAlien0)
end
end
antiAlien:addEventListener("collision", pickUpAntiAlien)