Runtime Error - attempt to call method removeSelf (a nile value) stack traceback: [C]: in function ‘removeSelf’
I’m having bomb.png (E_bomb1) in this code raining in randomn positions at a set time interval. When it reaches the bottom it removeself. So far this part of the code works really well.
It’s when I try to have it so that clicking on the E_bomb1s removes themselves that things begin to act weird.
Here is my code:
local \_H = display.contentHeight;
local \_W = display.contentWidth;
--Enemy gets touched
function touchBomb(enemy)
enemy.target:removeSelf();
end
--Bomb Code Begin
function E\_hit(bomb)
bomb:removeSelf();
end
--Enemy Bomb1 spawn
--Take note that "local" makes the E\_bomb variable local to one instant of it, as opposed to without local, which makes it apply
--to all variables.
function E\_bomb1Spawn()
local E\_bomb1
E\_bomb1 = display.newImage("E\_bomb1.png")
E\_bomb1.x = math.random( \_W )
E\_bomb1.y = -10
E\_bomb1.xScale = 1
E\_bomb1.yScale = 1
--Adding the E\_bomb1.height/2 covers the other half of the height when it touches the bottom.
transition.to( E\_bomb1, { time=3000, y= (display.contentHeight - display.screenOriginY) + E\_bomb1.height/2 , onComplete=function() E\_hit(E\_bomb1) end })
E\_bomb1:addEventListener("touch", touchBomb);
end
E\_bomb1Spawn()
--SpawnTimer
E\_bomb1Spawner = timer.performWithDelay(1000, E\_bomb1Spawn, -1);
--Bomb Code End
I originally had it so that touchbomb was just a copy ‘n’ paste of E_hit, but I started receiving “Runtime Error - attempt to call method removeSelf (a nile value) stack traceback: [C]: in function ‘removeSelf’” followed by it not working.
Now with this new version after a touch, the next few E_bomb1s that are transitioning down freeze in mid-air (though they can be removed by simply clicking on them).
What is going wrong? Is the event listener apply the removeself to all the other E_bomb1s present in the screen? Any suggestions? [import]uid: 44572 topic_id: 8151 reply_id: 308151[/import]