ID:1524411
 
(See the best response by Kaiochao.)
golddustarmor()
if(goldarmorcreation)
overlays-=obj/armorhp
view(8)<<"<b><font color='yellow'><small>Shield off."
goldarmorcreation=0
return
if(cdelay1)return
cdelay1=1
spawn(50)
cdelay1=0
view(8)<<"<b><font color='yellow'><small>Shield on."
var/obj/armorhp/K=new()
K.maptext="<b><font color=red><small>[round(maxhp/10)]"
overlays+=K
goldarmorcreation=1


Problem: The way I want this to work is, you activate the ability, and it gives you a shield. I want it to show a number under the user how much the shield is. It creates the overlay, but when the ability is deactivated, it doesn't get rid of the overlay.

Would anyone know why it does this?
Best response
You're asking why it doesn't work. I would've asked how to fix it, but here goes:

First off, this shouldn't even compile (unless you have variables called "obj" and "armorhp"):
overlays-=obj/armorhp


Secondly, you're (probably) trying to remove "/obj/armorhp", which is a type path, after adding "a new object instance", which is not equal to the thing you're trying to remove.
//  basically, you have this
some_object = new /obj/armorhp
overlays += some_object

// some time passes
overlays -= /obj/armorhp

// clearly, some_object != /obj/armorhp

That's pretty much why you shouldn't expect it to work. It's no different from doing this:
var list[0]
list += "A"
list -= "B"
// why wasn't "A" removed from the list?
Oh I see. How would I go about fixing this problem to fit the purpose I'm trying to make it serve?
In response to SinfulPhoenix
You need to save the unique thing that you're adding to overlays so you can remove that same exact thing. This is what variables are for.
// simple example

// the player
mob
// the variable: all procs of /mob know about it
var armor_overlay

// the proc: use the variable
proc/wear_armor()
armor_overlay = new /overlay_type
overlays += armor_overlay

// the other proc: use the variable again
proc/remove_armor()
// assuming we're already wearing the armor
// so we actually have something to remove.
overlays -= armor_overlay
Ah excellent, I won't even have to put it on a loop to keep checking if it needs to be removed