ID:141931
 
Code:
            if(usr.selected_weapon)
world<<"Returned true. There was a weapon the user had selected." //debug messages.
world<<"The type of weapon you have selected is [usr.selected_weapon.type]"
usr.overlays-=usr.selected_weapon.type //Here. Why does this not work?


Problem description:

I'm wondering why this doesn't work. I heard from a certain someone (:p) that once the object was created as an overlay it had no reference to the original. Therefore I'm using it's type path to remove it. I don't understand why this doesn't work. The debug messages I got back all basically said it should have worked. What's up?

You need to use the exact same value you've added to the overlays when you're removing it. So removing the type path will only work if you've added it by using something like overlays += type_path.
May want to show the code you're using to add the overlay.
In response to Kaioken
I said before, that's not true. Here, I'll prove it.

world
maxx = 10
maxy = 10
maxz = 1

turf = /turf/grass

mob
icon = 'icon.dmi'
icon_state = "mob"

verb
Halo()
if(!overlays.len)
var/obj/halo/O = new()
overlays += O
del(O)
else
overlays -= /obj/halo

obj
halo
icon = 'icon.dmi'
icon_state = "halo"

turf
grass
icon = 'icon.dmi'
icon_state = "grass"

In response to Kaioken
Here's the whole code.

obj
selected
icon='screen objs.dmi'
icon_state="select"
selected2
pixel_y=32
icon='screen objs.dmi'
icon_state="selected"
screen_type
var/selected
var/obj/gun/owner //The actual gun.
New()
..()
src.owner=usr.lastgun
Click()
//Selection icons
if(usr.on_screen_selected)
usr.on_screen_selected.overlays-=/obj/selected
if(usr.on_screen_selected2)
usr.on_screen_selected.overlays-=/obj/selected2
usr.on_screen_selected=src
var/y=new/obj/selected2()
usr.on_screen_selected2=y
var/i=new/obj/selected()
src.overlays+=i
src.overlays+=y
//____
if(!usr.playing)
return
if(usr.selection_in_progress)
return
usr.selection_in_progress=1
if(usr.selected_weapon)
world<<"Returned true. There was a weapon the user had selected." //debug messages.
world<<"The type of weapon you have selected is [usr.selected_weapon.type]"
usr.overlays-=usr.selected_weapon.type //Here. Why does this not work?
usr.selected_weapon=src.owner
usr.selected_weapon.dir=usr.dir
usr.overlays+=usr.selected_weapon
usr.ammo=src.owner.ammo
usr<<"<b>You have equipped <font size=5> \icon [src] </font> ([src])"
usr.selection_in_progress=0
In response to Speedro
Erm. What's going on?
In response to Speedro
My guess is that what you're trying to remove doesn't exist in the overlays list.
In response to Xooxer
How could it not though? I mean that's the problem, right? My overlays won't go away :/
In response to Speedro
Well, yeah. So whatever that variable refers to, it's not in the overlays. Whatever is in the overlays isn't that, so you're going to have to figure out what you're adding to the overlays. Like Kaioken said, it'd help to know how you're adding things to the overlays.
In response to Xooxer
It was in the whole code, but here it is:


usr.overlays+=usr.selected_weapon


I set usr.selected_weapon to whatever their weapon choice was. Like: obj/weapon/verb/select()/usr.selected_weapon=src
In response to Speedro
You added it as usr.selected_weapon, an object. You're trying to remove it by usr.selected_weapon.type, a text string. You should just try accessing it by the usr.selected_weapon variable without the type.

[Edit]
So, that probably won't work for you. Seems you can remove it by the type variable (which is not text, my mistake). I really don't know what your problem is, because this works for me: (with an instance of the over obj on the map so I can select it, the Test adds and removes the overlay properly.)

turf
icon = 'turf1.dmi'

mob
icon = 'mob.dmi'
var/obj/selected

verb
Test()
overlays += usr.selected
sleep(30)
overlays -= usr.selected.type

obj
over
icon = 'icon.dmi'
icon_state = "test"
layer = FLY_LAYER
pixel_y = 32

verb
Select()
set src in view()
usr.selected = src
In response to Xooxer
I thought it created an entirely new overlay on the screen... Yet somehow it works. Thanks. :p