Hi! I am new in lua programming and now I have a dude with the event
I have targets moving down on the screen, they are in a group called Dianas and I want know what diana is touched to remove it. here is the code
function generar( event )
score = score + 1
scoreTxt.text = score
local posX = math.random( 1 , 2 )
local posIzq = 75
local posDch = display.contentWidth - 75
if posX == 1 then
diana = display.newImage( “diana.png” , posIzq , -100)
else
diana = display.newImage( “diana.png” , posDch , -100)
end
dianas:insert( diana)
totalElementos:insert( dianas )
dianas:toFront( )
scoreTxt:toFront( )
end
generarDianas = timer.performWithDelay( 300, generar, -1 )
function getDeltaTime()
local temp = system.getTimer()
local dt = (temp- runtime) / (1000/30)
runtime = temp
return dt
end
function moverDianas( event )
local dt = getDeltaTime()
for i = dianas.numChildren,1,-1 do
if(dianas[i].y > display.contentHeight + 200) then
dianas:remove(dianas[i])
else
dianas[i].y = dianas[i].y + 15 * dt
end
end
end
Runtime:addEventListener(“enterFrame”, moverDianas )
function eliminarDiana( event )
if (event.phase == “began”) then
for i = dianas.numChildren,1,-1 do
if(dianas[i].) then
dianas:remove(dianas[i])
end
end
end
end
dianas:addEventListener( “touch”, eliminarDiana )
the problem is if I use diana to use the event, corona says it is nil and brake the game. Thx for your answers