Object removing itself error

So I’m following atutorial  and I get an error when I tap on an orb. Help please :smiley:

local \_W = display.viewableContentWidth local \_H = display.viewableContentHeight display.setDefault("background", 1, 0.972549, 0.862745) local mRand = math.random local o = 0 local time\_remain = 10 local time\_up = false local total\_orb = 20 local ready = false local soundtrack = audio.loadStream ("refangold.mp3") local pop\_sound = audio.loadSound("pop.mp3") local win\_sound = audio.loadSound("win.mp3") local fail\_sound = audio.loadSound("fail.mp3") local function trackOrbs(obj) obj:removeSelf() end local function spawnOrb() local orb = display.newImageRect("orb1.png", 60, 60) orb.x = mRand(40, \_W-40); orb.y = mRand(40, \_H-40) local function orbtouch(e) if(e.phase == "ended") then audio.play(pop\_sound) trackOrbs(self) end end orb:addEventListener("touch", orbtouch) end local tmr = timer.performWithDelay(20, spawnOrb, total\_orb)  
  1. Either fix your code so it doesn’t call trackOrbs() when the object is removed/invalid.

AND/OR

  1. Never use obj:removeSelf()

Use display.remove( obj ) instead.

local function trackOrbs(obj) -- UNSAFE obj:removeSelf() display.remove( obj ) -- SAFE end

Thanks for the fast response, now I don’t get an error but the object remains after being clicked on. What exactly is my option with “fixing my code so it doesn’t call trackOrbs()…”?

I am sorry.  I cannot help with re-coding. 

You are following an offsite and incredibly OLD tutorial.  It may have some value still, but the fact that it is 6 years old will put some aspects completely out-of-date and incompatible with modern Corona dev. 

That was in the Graphics 1.0 time-frame and we’ve moved way beyond that today.

You may be better served trying all the tutorials, guides, and at least some marketplace content (here are mine, some are very cheap; do not use SSK2 till you are experienced with Corona.) to learn first. 

Once you work through the modern content, you will be better armed to handle old examples.

Alternately, you can find a mentor or hope someone else here will have time to debug your code.

Sorry if this isn’t the answer you wanted.

PS - Your post is really great by the way, I simply have a limit on my available time.  Sorry!

I understand, thank you for the help, I’ll be sure to check out the tutorials and guides. 

Just to help… self is nil so that is why you are getting the error.

Change trackOrbs(self) to trackOrbs(orb)

Thank you SOOOOOOOO much, now I  can continue with the tutorial. 

  1. Either fix your code so it doesn’t call trackOrbs() when the object is removed/invalid.

AND/OR

  1. Never use obj:removeSelf()

Use display.remove( obj ) instead.

local function trackOrbs(obj) -- UNSAFE obj:removeSelf() display.remove( obj ) -- SAFE end

Thanks for the fast response, now I don’t get an error but the object remains after being clicked on. What exactly is my option with “fixing my code so it doesn’t call trackOrbs()…”?

I am sorry.  I cannot help with re-coding. 

You are following an offsite and incredibly OLD tutorial.  It may have some value still, but the fact that it is 6 years old will put some aspects completely out-of-date and incompatible with modern Corona dev. 

That was in the Graphics 1.0 time-frame and we’ve moved way beyond that today.

You may be better served trying all the tutorials, guides, and at least some marketplace content (here are mine, some are very cheap; do not use SSK2 till you are experienced with Corona.) to learn first. 

Once you work through the modern content, you will be better armed to handle old examples.

Alternately, you can find a mentor or hope someone else here will have time to debug your code.

Sorry if this isn’t the answer you wanted.

PS - Your post is really great by the way, I simply have a limit on my available time.  Sorry!

I understand, thank you for the help, I’ll be sure to check out the tutorials and guides. 

Just to help… self is nil so that is why you are getting the error.

Change trackOrbs(self) to trackOrbs(orb)

Thank you SOOOOOOOO much, now I  can continue with the tutorial.