Object Doesn't get removed (again)

Now another object doesn’t remove, it stays on screen.
Even before removal print says what weapon is nil, but it is still on screen.

Example of my code:

function a()
  local weapon = display.newImageRect(...)
  ...
end

function b()
  print(weapon)
  display.remove( weapon )
end

It’s a scope thing. You defined weapon in a() which prevents it being called from b(). You can either:

local weapon

function a()
    weapon = display.newImageRect(...)
end

function b()
    display.remove(weapon)
end

OR

function a()
   weapon = display.newImageRect(...)
end

function b()
    display.remove(weapon)
end

Scope tutorial for more information.

3 Likes

Thanks, now I understand why sometimes people use just local object

And how do I remove particles (emitters)?

ok, nevermind I removed it with display.remove()