ID:1264270
 
(See the best response by DarkCampainger.)
Code:
//Relevant bits

// Equipment Stuff
obj
var
equipment = 0
equipped = 0
position = 0
Click()
..()
if(equipment) equip(usr)
proc
equip(mob/m)
if(loc != m) return
if(!equipped)
position = length(m.k_overlays)
layer = FLOAT_LAYER - 1
m.AddOverlay(src)

else
m.RemoveOverlay(src)
m.preserveLevels(position)
position = 0
layer = initial(layer)
equipped = !equipped
Clothes
equipment = 1
inventory = 1



Shirt
icon = 'Shirt.dmi'
Pants
icon = 'Pants.dmi'

// Race Picking Stuff

mob/Player
var
tmp/list/spawn_at = list(100,95,1)
tmp/list/def_clothes = list(/obj/Clothes/Pants, /obj/Clothes/Shirt)

New(ready=0, size = "Medium")
..()
if(!ready) return
spawn() create(size)

proc
create(size)
while(!hascreated) sleep(5)
loc = locate(spawn_at[1], spawn_at[2], spawn_at[3])
while(!hasloaded) sleep(5)
check_clothes()
update_inv()

check_skills()

check_clothes()
for(var/x in def_clothes)
var/obj/Clothes/c = new x(src)
//c.equip(src)
usr = src
c.Click()

// Character Creation Stuff
proc
new_def(mob/m, mob/p)
p.key = m.key
p.defaults(1)
p.save_proc()

mob
proc
s_newchar()
var csize, cname, crace
if(winget(src, "smed_radio", "is-checked") == "true") csize = "Medium"
else if(winget(src, "slarge_radio", "is-checked") == "true") csize = "Large"
else csize = "Small"
crace = winget(src, "selectedRace", "text")
var/t2p = text2path("/mob/Player/[crace]")
var/mob/Player/c = new t2p(1, csize)
c.hascreated = 1
new_def(src, c)


Problem description:

Put simply, this is my issue. When a character is created, it automatically get's equipped with some clothes and hair. The clothes that are equipped to it however are bugged in that they do not change direction with the player.

It's only temporary though, after calling equip() once again it fixes the issue. Yet, it still exists, and is annoying. Does anyone have a clue why?

Here ya go.

    proc
AddOverlay(A)
if(!k_overlays) k_overlays = list()
if(!A) return
k_overlays += A
ReArrangeO()
UpdateOverlays()


ReArrangeO()
var list/strangers = list()
var obj/o
for(var/x in k_overlays)
if(istype(x, /obj))
o = x
if(o.equipment) strangers += o
k_overlays -= strangers
k_overlays += strangers

UpdateOverlays()
overlays = k_overlays
Best response
Kitsueki wrote:
Code:
>               //c.equip(src)
> usr = src
> c.Click()


Why did you swap the commented code for that usr-hack? It would make sense if this was the source of your strange behavior, as it's the main difference between the "broken" first call and "working" second call. If you wanted a common code path between loading and a player clicking it, create an intermediary "Activate(mob/m)" proc or something they both call.
In response to DarkCampainger
That was a bit just to make sure usr was the right person, I just forgot to remove it when posting this haha.
I don't see how asking me about my experience solves this issue. Just in case your comment has a legitimate purpose, I'm not new to programming.
As for the first bit, I experimented around with the parameters, and it doesn't seem to care whether I pass the starting location in, or some other data. Since I don't locate it right away, it's fine that I don't do anything for the location in the new instruction.

As for the k_overlays part, it's not redundant to store them in a separate list because you have more flexibility than with just the overlays variable. Having this solves a lot of overlays bugs that pop up, since I can just reset the overlays list each time I want to modify it without any issues.

I'm not asking for anything to be handed out to me, I just care about fixing this bug. I wont reject offers to teach me a better way to handle things, though.

I'm not claiming to be a master programmer, nor do I care to be. I'm just trying to create a game, and I have less time to worry about getting the code perfect as opposed to developing the game further.

Are people always this rude and unhelpful when someone asks for help?
I actually took the time out to read what was going on, and it dawned on me that I just edited it to work after I changed for equipment is handled. Used to be, it was just typed as /Equippable, so thats where the istype() call came in. Now that it's regular old /obj, I can edit it to this.

        ReArrangeO()
var list/strangers = list()
for(var/obj/o in k_overlays) if(o.equipment) strangers += o
k_overlays -= strangers
k_overlays += strangers


Which is much simpler. I try to keep these broken up into separate procs to reduce the overhead when I just want to update the overlays without adding or removing things.
overlays doesn't store things the same as a normal list however, so the extra list is necessary. I'm not sure how you're suggesting I keep the flexibility without the extra list.

Edit: Are you suggesting I do..

overlays = list()
overlays += k_overlays
Thank you, Galactic. You're awesome.