ID:141685
 
Code:
world
mob = /mob/player
mob/player
var
list/selected = list()
Stat()
statpanel("Selected Units:")
for(var/x in selected)
stat(x)
mob/units
var
faction = "h"
Click()
var/mob/player/p = usr
var/image/I = image('Select.dmi',src,faction,layer=MOB_LAYER+1)
if(src in p.selected)
// overlays -= I
p.selected -= src
p.client.images -= I
return 1
if(!(src in p.selected))
// overlays += I
p.selected += src
p << I
return 1


Problem description:

When a client logs in, he is automatically changed to a /mob/player (line 2). When I click on a /mob/unit, the overlay is added and the unit is added to my select list, when I click on it again, it is removed from my select list, but the [image] overlay remains there.

Why isnt the [image] overlay removed and how would I remove it?

Note: If I replace the "p << I" and "p.client.images -= I" with OVERLAYS (commented lines), it works fine.

Thanks!
Delete the image rather than removing it from the images list. Even if it did work, it would be bad. This is because the image would never get deleted (it would still have a loc, which would prevent the garbage collector from getting), and it would waste resources.

Also, use else instead of the same if() twice with a ! operator in one.

And your problem lies in the fact that you're removing a new image, not the old one, by the way. Keep some form of reference to the old image, and then delete it rather than making a new one and deleting it.

Remember, images aren't overlays unless you add them to the overlays list; they are like objs and mobs.
In response to Jeff8500
Alright, thanks.

world
mob = /mob/player
mob/player
var
list/selected = list()
Stat()
statpanel("Selected Units:")
for(var/x in selected)
stat(x)
mob/units
var

faction = ""
image/select
New()
select = image('Select.dmi',src,faction,layer=MOB_LAYER+1)
..()
Click()
var/mob/player/p = usr
if(src in p.selected)
p.selected -= src
p.client.images -= select
return 1
else
p.selected += src
p << select
return 1


This works ;)