ID:142131
 
Code:
obj/var/equip
obj/clothing/var/been_dblclicked
obj
clothing
icon = 'clothing.dmi'
var
clothing_defense = 0 // instantiate the type as a number
clothing_strength = 0



obj
clothing
proc
Equip()
if(src.equip) //if it's not on, add it
src.layer = CLOTHING_LAYER // the layer for all clothes
usr.overlays += src
usr.added_on_defense += src.clothing_defense
src.suffix = " equip"
return
if(!src.equip) //if it's on, take it off
usr.added_on_defense -= src.clothing_defense
src.suffix = ""
usr.overlays -= src
return


DblClick()
set src in usr.contents
if(been_dblclicked)
been_dblclicked = 0
src.equip = 0
Equip()
return
else
been_dblclicked = 1
src.equip = 1
Equip()
return


Problem description:Well I really didn't want to ask this because I wanted to figure this out by myself but since I've already put like a few hours of troubleshooting into this I'll ask here anyways.

The problem is that once the overlay is added, if you DblClick again in your contents on the item so that equip now equals 0, everything BUT the removing of the overlay works under the if(!src.equip) statement. That's good but I want the overlay to be removed and it's not working.

Overlays are really screwy; you can't access a single overlay after it's been added. You can get around this by setting overlays to null and then re-adding all the overlays.

mob/var/list/CurOverlays = list() //Reference to overlays


obj
clothing
proc
Equip()
if(src.equip) //if it's not on, add it
src.layer = CLOTHING_LAYER
usr.CurOverlays += src
usr.overlays += src
usr.added_on_defense += src.clothing_defense
src.suffix = " equip"
return
if(!src.equip) //if it's on, take it off
usr.added_on_defense -= src.clothing_defense
src.suffix = ""
usr.CurOverlays -= src
usr.overlays = null
usr.overlays += usr.CurOverlays
return
In response to Glarfugus
Glarfugus wrote:
Overlays are really screwy; you can't access a single overlay after it's been added. You can get around this by setting overlays to null and then re-adding all the overlays.

You can't access a single overlay by looping through the list, but you should be able to remove it from the overlays list just fine. The reference shows an example of this, although it uses icon objects or typepaths rather than an atom. The main exception is that this doesn't work if they've been saved and reloaded.
In response to Jon88
I just looked at a thread in Bug Reports and came across a post(ID:635671) which would show why the overlays aren't being removed. If Falacy is correct, then he can't remove overlay objects directly if he's modified them. A fix for this would be the code in my above post, or to possibly just remove the overlay before modifying the object.
In response to Glarfugus
Glarfugus88 your code worked but it removes all of the overlays that I have on, as opposed to just the one that I'd like to remove.

Jon88 you're right though so is there an alternative to using overlays by adding an icon to your icon to appear as an overlay and then being able to remove it without changing the icon's state in your inventory?
In response to Glarfugus
obj
clothing
proc
Equip()
set src in usr.contents
if(src.equip) //if it's not on, add it
src.layer = CLOTHING_LAYER
usr.added_on_defense += src.clothing_defense
src.suffix = " equip"
usr.overlays += src
return
if(!src.equip) //if it's on, take it off
usr.overlays -= src
usr.added_on_defense -= src.clothing_defense
src.suffix = ""
return


You're right Glarfugus the issue was just the order of modification to the item and it's result on the icon. Apparently you can remove overlays only if it hasn't been modified directly associated with the object it's attached to, in this case, the objs clothing_defense in addition to the mobs added_on_defense vars. So if you remove the item right after it's been added on, in other words, is the only way you can get the effect of removing it. You have to assign the vars to the object first that are associated with the mob it's going to be attached to, then you make the overlay effect. Then when removing it, you first remove the overlay effect, and then modify the objects vars that are attached tot he mob. What a strange bug >_>'. Thanks guys it's working now.
In response to DragonMasterGod
It's not a bug, it's intended and logical. You need to remove the identical value you've added to the overlays list in order to remove it later. In case of using an object, you need one with identical vars.
In response to Kaioken
..vars that has something to do with the image of the object, right?
In response to Jemai1
Yeah. But I'm not sure about that 'cause in that case the image is still being removed even after it's equip var is being changed. That's why I think it might be vars that connect both the image and the mob wearing it together that when the vars are edited might trigger it to not remove.
In response to Jemai1
Apparently not, but it's intended nonetheless, and I can see a plus. Maybe it's more difficult for them to make it count only for the visual vars. As an alternative, if you're sure you don't change the equipment's icons on runtime, you could just add and remove the object's type path, which will of course always work as the value is identical.
In response to Kaioken
What I do is make a new list Overlays and just treat it as the normal overlays var. Then to make them show up I simply re-write everything in the new list to usr.overlays.

Now, you want to be careful when you save overlays, as they will be added to the icon and you won't be able to get them off no matter what tricks you use.

Heres an example of what I do:
mob/var/list/Overlays = list()
mob/proc/update_overlays()
src.overlays = null
for(var/obj/O in src.Overlays)
src.overlays += O

//Then when you want to add overlays
mob/verb/whatever()
//adding overlays for whatever reason
src.Overlays += obj
src.update_overlays()

//And just before you save:
mob/proc/save()
src.overlays = null
//save code here

src.update_overlays()

In response to Smokey Joe
Smokey Joe wrote:
What I do is make a new list Overlays and just treat it as the normal overlays var. Then to make them show up I simply re-write everything in the new list to usr.overlays.

Now, you want to be careful when you save overlays, as they will be added to the icon and you won't be able to get them off no matter what tricks you use.

Heres an example of what I do:
> mob/var/list/Overlays = list()
> mob/proc/update_overlays()
> src.overlays = null
> for(var/obj/O in src.Overlays)
> src.overlays += O
>
> //Then when you want to add overlays
> mob/verb/whatever()
> //adding overlays for whatever reason
> src.Overlays += obj
> src.update_overlays()
>
> //And just before you save:
> mob/proc/save()
> src.overlays = null
> //save code here
>
> src.update_overlays()
>

That's exactly what i do too, works pretty well.