ID:139945
 
Code:
mob/var/list/Overlys = list()

mob
proc
Add_Overlays(obj/o)
if(!o) return

src.Overlys += o
src.Refresh_Overlays()

Del_Overlays(obj/o)
if(!o||!Overlys.Find(o)) return 0

src.Overlys -= o
src.Refresh_Overlays()

Refresh_Overlays()
src.overlays = null
for(var/I in Overlys)
src.overlays += image(I)

mob
var
list/clones = list()

verb
Make_Copy(mob/M in oview(5))
usr.clones += M


Become_Person(mob/M in clones)
usr.Overlys = null
for(var/I in M.Overlys) // also tryed var/obj/I if that matters.
usr.Overlys += I
spawn(1) usr.Refresh_Overlays()


Problem description:
This is a tiny bit of code that i put togheter to make a clone ability, now.. my game is set in a way that the players overlays are handeled trough a list called Overlys.(as shown). So i thought i could just make a for loop and add the player in "clones" overlys to the player trying to clone's overlys, and that way "copy" it.

This however doesn't seem to be working, allthough i have not tested it under "good conditions".

My own guess would be that adding M to clones does not add what i think it adds.

Oh and while im at it, When i wear shirts etc.. the walking stuff is allright, but when flicking the "punch" the shirt acts as if it does not have a "punch" icon_state by dissapearing really quick, yet there is a "punch" icon_state. any reasons to why this might be happening?
Apparently M.Overlys doesn't contain anything, which could mean you're adding them directly instead of your system. Adding debug output would make it easy to see where things go wrong.
<font color=yellow size=+1>EDIT:</font> I didn't notice that you're doing src.overlays += image(I) instead of merely adding I as supplied to the proc (trusting that it's already in the form of one of the supported data types). That's going to fail whenever the argument to Add_Overlay() isn't simply a reference to an icon file, because the first argument to image() has to be an icon file. This is supposedly your main problem there, but the rest of what I've said still stands as is.


But since we know for a while that it's possible to interact with (but not modify) the contents of the under/overlays list, you most likely don't need any such contrived backup-Overlays-list anymore at all. I may come up with a library sometime for clean under/overlays usage.

Lastly, since what the overlays var contains is really a /list object, if you want to copy overlays from one atom to the other, you can just set their one atom's overlays var to the other's.

In a normal situation, that would make both atoms' vars refer to the same list object. Therefore when you change this list through any of them, the changes will appear on both atoms, since they both have the same list. So if you don't want that, you would've had to use Copy() so both atoms have separate lists.

However, we're dealing with a special built-in var here. All built-in lists (and their vars) are special in one way or another.
You can't actually modify the value of the overlays var. If you try to, it will seem to work, but DM just "tricks" you by working around the limitation. If you try to set the overlays var to a different list, DM will simply empty the existing list in the overlays var, then add the different-list's contents to it. So since you still end up with the original overlays list intact, there are still 2 separate lists, you don't have to Copy().
//Normal vars:
var/list/L = new
var/list/B = L //B contains the same list as L
//Special var:
var/list/L = list(...)
mob.overlays = L //overlays doesn't now contain the same list as L

//instead, "mob.overlays = L" is equivalent to this:
mob.overlays.Cut()
mob.overlays += L

//if you write "mob.overlays = L.Copy()", you get a virtually same result
In response to Kaioken
Hey, and thanks for the reply, i've got it mostly figured out now.

I originally did src.overlays += I, but then read somewhere that since saving overlays was such a nono you would be better off using image(). regardless, changed it back to simply I.

I'm still having trouble with items and flicking though.
Maybe it's something new caused by an update that i have missed, but i got my shirt and pants in seperate .dmi files, each file containing the normal standing, movement and punching icon states, however, when i flick "punch". the pants dissapear as if they had no punch icon state.

EDIT: The problem is resolved. The length of the icon states where different thus the pants icon state ran out before the players icon state. Geez, to think i spendt this long to notice :P