help me by telling me why this does not work please!

hi i am 13 years old and need help improving my code as well as help in the way that someone tell me
why this does not work. Thank you!
local physics = require(“physics”)
physics.start()

physics.setGravity( 0, 0 )

physics.setDrawMode(“hybrid”)

local back = display.newImage(“bkg_bricks.png”)

local function BloonSpawn ()
local balloon = display.newImage(“red_balloon.png”)
balloon.x = math.random(50, 275 )
balloon.y = display.contentHeight / 1 + 100
physics.addBody(balloon, { bounce = 0.4, friction = 0.4, radius = 43})

end

function balloonbreak ( event )

balloon:removeSelf()
end

timer.performWithDelay( 500, BloonSpawn, 100)
balloon:addEventListener(“touch”, balloonbreak)
[import]uid: 215700 topic_id: 36253 reply_id: 336253[/import]

Hi there,

Do you receive any errors in the console window when you run the code? The errors will usually point to the line that is causing the problem.

I think the issue is in your balloonbreak function. The line [lua]balloon:removeSelf()[/lua] refers to a variable [lua]balloon[/lua] which doesn’t exist in the scope of the function. Try deleting that line and replacing it with [lua]event.target:removeSelf()[/lua].

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36253 reply_id: 144015[/import]

Thank you so much Andrew! I will try that out. Thanks! [import]uid: 215700 topic_id: 36253 reply_id: 144018[/import]

Hi there,

Do you receive any errors in the console window when you run the code? The errors will usually point to the line that is causing the problem.

I think the issue is in your balloonbreak function. The line [lua]balloon:removeSelf()[/lua] refers to a variable [lua]balloon[/lua] which doesn’t exist in the scope of the function. Try deleting that line and replacing it with [lua]event.target:removeSelf()[/lua].

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36253 reply_id: 144015[/import]

Thank you so much Andrew! I will try that out. Thanks! [import]uid: 215700 topic_id: 36253 reply_id: 144018[/import]

Hi there,

Do you receive any errors in the console window when you run the code? The errors will usually point to the line that is causing the problem.

I think the issue is in your balloonbreak function. The line [lua]balloon:removeSelf()[/lua] refers to a variable [lua]balloon[/lua] which doesn’t exist in the scope of the function. Try deleting that line and replacing it with [lua]event.target:removeSelf()[/lua].

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36253 reply_id: 144015[/import]

Thank you so much Andrew! I will try that out. Thanks! [import]uid: 215700 topic_id: 36253 reply_id: 144018[/import]

Hi there,

Do you receive any errors in the console window when you run the code? The errors will usually point to the line that is causing the problem.

I think the issue is in your balloonbreak function. The line [lua]balloon:removeSelf()[/lua] refers to a variable [lua]balloon[/lua] which doesn’t exist in the scope of the function. Try deleting that line and replacing it with [lua]event.target:removeSelf()[/lua].

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36253 reply_id: 144015[/import]

Thank you so much Andrew! I will try that out. Thanks! [import]uid: 215700 topic_id: 36253 reply_id: 144018[/import]