ID:264635
 
Code:
        UpdateOverlays()
for(var/obj/i in src.overlays)
i.icon_state=src.icon_state
equipment
layer=FLY_LAYER
var
uname
ename
robe
icon='robe.dmi'
icon_state="stand"
uname="Robe"
ename="Robe - Equipped"
Click(mob/players/p)
p=usr
if((src in p.contents) && (!src.suffix))
src.suffix="Equipped"
src.name=ename
p.overlays+=src
p.UpdateInventory()
else if((src in p.contents) && (src.suffix=="Equipped"))
src.suffix=""
src.ename=src.uname
p.overlays-=src
src.layer=OBJ_LAYER
p.UpdateInventory()
else if(src in oview(1,p))
p.contents+=src
src.icon_state=""
p.UpdateInventory()
else
return


Problem description:
I'm trying to make it so when the player icon state is updated, their overlays icon state will update to the players icon state as well, but it's not updating. On top of that, the overlay isn't being removed. I switched the p.overlays to o.icon and it removed, but it shows underneath the the player when being equipped. And doing a cross of the two doesn't work. What's wrong?
From the reference:

This is a list of icons which are displayed on top of the object's main icon.

The individual items in the list may not be directly accessed, since they are stored in a special internal format. However, the list operators +=, -=, and the procedures Add, Remove, and Cut work normally.




IE: You can't edit an overlay once it has been added, you must remove it and add the new state that you want.
Ulterior Motives wrote:
Code:
>       UpdateOverlays()
> for(var/obj/i in src.overlays)
> i.icon_state=src.icon_state
> equipment
> layer=FLY_LAYER
> var
> uname
> ename
> robe
> icon='robe.dmi'
> icon_state="stand"
> uname="Robe"
> ename="Robe - Equipped"
> Click(mob/players/p)
> p=usr
> if((src in p.contents) && (!src.suffix))
> src.suffix="Equipped"
> src.name=ename
> p.overlays+=src
> p.UpdateInventory()
> else if((src in p.contents) && (src.suffix=="Equipped"))
> src.suffix=""
> src.ename=src.uname
> p.overlays-=src
> src.layer=OBJ_LAYER
> p.UpdateInventory()
> else if(src in oview(1,p))
> p.contents+=src
> src.icon_state=""
> p.UpdateInventory()
> else
> return
>

Problem description:
I'm trying to make it so when the player icon state is updated, their overlays icon state will update to the players icon state as well,

Last time I tested BYOND does that automaticaly.

On top of that, the overlay isn't being removed. I switched the p.overlays to o.icon and it removed, but it shows underneath the the player when being equipped. And doing a cross of the two doesn't work. What's wrong?

src.overlays-=src

This is supposed to work, I hope you are not saving the overlays using BYOND sav system.
for(var/I in usr.overlays)
if(I.icon=='robe.dmi')
usr.overlays-=I

Try this ?

And I didn't get that o.icon, you mentioned cause I don't see a variable o here.
But seems that you are using icon_arithmetic, though that is of no need.

But as a question, do you really have to add an object as overlay?
Why don't you add an overlay as icon instead of an object,but this can still work.

Try Rebuilding you overlays every time you update, I don't feel that would be laggy, if you can manage.Since you can't edit overlays after you add them, prefer building them.

I always thought BYOND changed the icon_state of the overlay automatically - the last time I programmed in DM (BYOND 454), it was like that.
In response to Getenks
I always thought BYOND changed the icon_state of the overlay automatically - the last time I programmed in DM (BYOND 454), it was like that.



As far as I can tell what your actually talking about: An overlays icon is only going to "change" if its a directional icon, the state itself will not change once it has been added to an objects overlays.
In response to Jotdaniel
proc/UpdateOverlays()
for(var/obj/i in src.overlays)
new i
i.icon_state=src.icon_state
src.overlays.Cut(i)
src.overlays+=i

So, would this work?
In response to Ulterior Motives


As far as I can tell what your actually talking about: An overlays icon is only going to "change" if its a directional icon, the state itself will not change once it has been added to an objects overlays.

Overlays icon would change its state too.
I have checked this.(454).

And Why do you use Cut()? Remove would be better
In response to Getenks
Getenks wrote:
> src.overlays-=src

This is supposed to work, I hope you are not saving the overlays using BYOND sav system.

No, there is no save system in this game.

> for(var/I in usr.overlays)
> if(I.icon=='robe.dmi')
> usr.overlays-=I
>

Try this ?

Due to the fact I have more then one obj that can be used as an overlay this would be inefficient. Also you can't read a variables icon without a parent.

for(var/obj/i in p.overlays)
if(i.icon==src.icon)
p.overlays-=src

Might work better. =P But that doesn't do it either. Neither does-
for(var/i as icon in p.overlays)
if(i==src)
p.overlays-=src


And I didn't get that o.icon, you mentioned cause I don't see a variable o here.

I messed up there. I meant I did p.overlays-=src.icon and p.overlays+=src.icon. This works, but when adding it, it appears under the the player. And doing p.overlays+=src, and p.overlays-=src.icon doesn't work. It still doesn't remove the icon.

But as a question, do you really have to add an object as overlay?

Well, if I could figure out how to make the overlay appear over the player as an icon, then read the icon later so I can change the state then I would. Part of the reason I am using the obj as an overlay is because it's easier doing for(var/obj/o in src.overlays) because using a regular variable without a type won't let you modify the icon state.
In response to Ulterior Motives
Okay, after testing this doesn't work.
You don't need that UpdateOverlays() proc at all. When adding something to overlays, make sure its icon_state is null. If it is, then the icon_state will always match that of the player.
In response to Garthor
I would think so also, but the player and objects icon_states do start off as blank. And all their icon states match up as well.
In response to Ulterior Motives
If they were actually blank you would get the behavior you wanted. As you are not getting the behavior you want, they are not blank.
In response to Ulterior Motives
Ulterior Motives wrote:
Getenks wrote:
> > src.overlays-=src

This is supposed to work, I hope you are not saving the overlays using BYOND sav system.

No, there is no save system in this game.

> > for(var/I in usr.overlays)
> > if(I.icon=='robe.dmi')
> > usr.overlays-=I
> >

Try this ?

Due to the fact I have more then one obj that can be used as an overlay this would be inefficient. Also you can't read a variables icon without a parent.

Yes you can read, and you can change
for(var/icon/I in p.overlays)
if(I=='robe.dmi')
I.icon_state="required"

I believe that works


> for(var/obj/i in p.overlays)
> if(i.icon==src.icon)
> p.overlays-=src
>

Might work better. =P But that doesn't do it either. Neither does-
> for(var/i as icon in p.overlays)
> if(i==src)
> p.overlays-=src
>

And I didn't get that o.icon, you mentioned cause I don't see a variable o here.

I messed up there. I meant I did p.overlays-=src.icon and p.overlays+=src.icon. This works, but when adding it, it appears under the the player. And doing p.overlays+=src, and p.overlays-=src.icon doesn't work. It still doesn't remove the icon.

But as a question, do you really have to add an object as overlay?

Well, if I could figure out how to make the overlay appear over the player as an icon, then read the icon later so I can change the state then I would. Part of the reason I am using the obj as an overlay is because it's easier doing for(var/obj/o in src.overlays) because using a regular variable without a type won't let you modify the icon state

Prefer using icon as the overlay, if you are not much sure about objs


The point Garthor mentioned is the answer to your Q.
try keeping the object icon_state = "", and BYOND will automatically change its state
In response to Garthor
I guess it wasn't. =P I'm surprised it even showed up, it was set to an icon_state that doesn't exist.