[Resolved] Simple embarrassing question

Ok, I’ve spent alot of time learning lua the past 5 months working on my project. However, I am brain dead right now and can’t seem to get a simple function to work lol. Someone please tell me what I’m doing wrong. I am displaying objects on the screen and when you touch them, it disappears. I can’t seem to make the objects disappear for some odd reason:

[lua]
local physics = require(“physics”)
physics.start()

local createCircle
local createCircle1
local tapCircle

createCircle = function()
local circle = display.newCircle(0, 0, 40)
circle.x = 200; circle.y = 140
physics.addBody(circle, “static”)

circle:addEventListener(“tap”,tapCircle)
end

circleTimer = timer.performWithDelay(2000, createCircle, 5)

createCircle1 = function()
local circle1 = display.newCircle(0, 0, 50)
circle1.x = 300; circle1.y = 250
physics.addBody(circle1, “static”)

circle1:addEventListener(“tap”,tapCircle)
end

circleTimer1 = timer.performWithDelay(3000, createCircle1, 7)

function tapCircle(event)
if event.phase == “ended” then
event.target:removeSelf()
end
end
[import]uid: 69494 topic_id: 30790 reply_id: 330790[/import]

Looking at it… when the tapCircle function is executed, the event variable is nil so nothing gets executed inside the if statement.

This is because the circle and circle1 variables a local to their createCircle functions. Move the local circle and local circle1 declarations outside the functions and this should work.

Some things to note…
Before removing an object in the tapCircle function, remove the object’s physics and remove the objects eventListener.

Hope this helps!
–john [import]uid: 114363 topic_id: 30790 reply_id: 123250[/import]

You are using the “tap” event listener which doesn’t have phases but in your listener function you are doing an if event.phase == “ended”. Since there are no phases you are basically coming out with nil == “ended” so it’s never executing the rest of the code.

To fix either remove the if statement or change “tap” to “touch”. [import]uid: 147305 topic_id: 30790 reply_id: 123251[/import]

It works now! Thank you schizoid2k and budershank! [import]uid: 69494 topic_id: 30790 reply_id: 123254[/import]

Looking at it… when the tapCircle function is executed, the event variable is nil so nothing gets executed inside the if statement.

This is because the circle and circle1 variables a local to their createCircle functions. Move the local circle and local circle1 declarations outside the functions and this should work.

Some things to note…
Before removing an object in the tapCircle function, remove the object’s physics and remove the objects eventListener.

Hope this helps!
–john [import]uid: 114363 topic_id: 30790 reply_id: 123250[/import]

You are using the “tap” event listener which doesn’t have phases but in your listener function you are doing an if event.phase == “ended”. Since there are no phases you are basically coming out with nil == “ended” so it’s never executing the rest of the code.

To fix either remove the if statement or change “tap” to “touch”. [import]uid: 147305 topic_id: 30790 reply_id: 123251[/import]

It works now! Thank you schizoid2k and budershank! [import]uid: 69494 topic_id: 30790 reply_id: 123254[/import]