ID:1030344
 
(See the best response by Kaiochao.)
Problem description:
Hey everyone, I have a question for those of you who are a bit creative. Overlays and Underlays are quite a wonky things really.. They can get bugged up when the references are screwed with to the icons they're displaying.

I believe it was DarkCampainger who suggested I set their names to "" and then add them on as overlays, which did a good job of handling them.. until it came to saving and reloading them.

I'm trying to think up a method of being clear and secure with this, so here's what I have so far.

I'm thinking to give all obj's the player can pick up, or add to their underlays.. An 'equipped' variable. Each time overlays is updated, a proc would go through and clear the overlays, then re add everything in their content's which has the equipped var turned on. This could be a better reference, so that even if the overlays somehow get bugged all the items are re added in their correct state. Not sure if it's the best way however.

Anyone have any alternative methods to better handle these?

Best response
Use Forum_account's Overlays library to handle your overlays in a way that won't bug them up. The idea when working with overlays/underlays is to always remove the overlay before modifying its variables, and then re-add it. The library gives you procedures to get/set overlay variables by automatically doing that for you.
I'm checking this out, and it's pretty neat. After a bit of reading both the library and the demo I have to ask. Do I have to create a variable in the mob for each overlay I want to add on? The amount of items which can be equipped is unlimited in my project, so there's no way I can save the overlays that way...
In response to Kitsueki
Learn to utilize lists and "unlimited" becomes easy. It's not like you're saving each variable individually, right?
I'm not sure I follow, let me post what I'm trying to do with it, and maybe you can help me from there.

obj
Clothes
Click()
usr.overlay(src.icon)
/*
var/nname
if(loc == usr)
nname = name
name = null
if(!equipped)
usr.overlays += src
equipped = 1
else
usr.overlays -= src
equipped = 0
name = nname*/

layer = FLOAT_LAYER - 1
var
equipped = 0
Boots
icon = 'Boots.dmi'


It appears, that all you have to do is call overlays() and give it some info in the parameters to use, which I'm doing here, yet equipping it doesn't work. Are you saying I should create a list var for the mob, and save each of these as an addition to the list?
In response to Kitsueki
When you call usr.overlay(src.icon), you're really making an /Overlay object. If you want to modify or remove the overlay, you need to use the Overlay procedures given to you by the library.
The /Overlay obj is saved in usr's contents though, correct?
Also, how would I access this thing in said list? I think I could just use Find(), probably. I get the procedures well enough, well.. except this;

Overlay
var
atom/owner
obj/overlay_obj
image/image_obj
visible = 1

rgb = ""
list/viewers
image = 0

maptext_width = 32
maptext_height = 32

New(mob/o, icon, icon_state = null, layer = null)

overlay_obj = new() // new() what? New obj?


Also, when saving and loading, it's fine to leave the references as they are? I'm under the impression that saving references should always be avoided.

Edit: Got it working by doing as you suggested. Partially at least.. Accessing this is going to be awkward though.
usr.Overlays += usr.overlay(src.icon)

Well, I figured it out. With a bit of reading and playing around with this, I ended up with this working system:

obj
Clothes
Click()
var/Overlay/o
if(!olayed)
usr.Overlays += usr.overlay(src.icon)
olayed = 1
equipped = 1
position = length(usr.Overlays)
else
o = usr.Overlays[position]
o.Toggle()
equipped = !equipped
layer = FLOAT_LAYER - 1
var
equipped = 0
olayed = 0
position = 1


Thanks for showing me this library Kaiochao, it's pretty awesome.

Edit: Well, This is odd. When I try to load the character, I'm getting this;

runtime error: Cannot read null.layer
proc name: New (/Overlay/New)
source file: FA_Overlays.dm,141
usr: null
src: /Overlay (/Overlay)
call stack:
/Overlay (/Overlay): New(null, null, null, null)
Kitsuuu (/mob): load proc()
Kitsuuu (/mob): load char()
the loadchar img (/obj/loadchar_img): Click(null, "Mappane.MainMap", "icon-x=72;icon-y=34;left=1;scr...")


Seems the layer is screwed up. Might be because of saving it in a list?

This is the code that's running
Overlay
var
atom/owner
obj/overlay_obj
image/image_obj
visible = 1

rgb = ""
list/viewers
image = 0

maptext_width = 32
maptext_height = 32

New(mob/o, icon, icon_state = null, layer = null)

overlay_obj = new()
overlay_obj.icon = icon

if(layer != null)
overlay_obj.layer = layer
else
overlay_obj.layer = o.layer

overlay_obj.maptext_width = 32
overlay_obj.maptext_height = 32

owner = o

if(icon_state != null)
overlay_obj.icon_state = icon_state

owner.overlays += overlay_obj