ID:322958
 
Okay, so it's been a while since I've actively done any programing. Which means that I am fairly rusty on some things, and that brings me to the point of all of this.

I'm working on a new project to get back into the swing of things and that means I get to learn how skins work once and for all. So I've been going over LummoxJR's Makind Skins in Byond 4.0 and I had a few questions about some of the code in the Lesson 2 project files.

Mostly I was curious if one of you would be so kind as to look over this and let me know if I am understanding everything that is happening here correctly.

Block in question
proc/Equip(obj/O)
if(!O || !O.slot) return
if(equipment && equipment[O.slot])
Unequip(equipment[O.slot])
if(equipment && equipment[O.slot]) return // unequip failed
if(!equipment) equipment = new
equipment[O.slot] = O
UpdateInventory()
UpdateEquipment()


The same block fully expanded with comments containing my thoughts on what is going on.

proc
Equip(obj/O)
if(!O || !O.slot) // If there is no object or the object does not have a slot,
return // return and end proc.

if(equipment && equipment[O.slot]) // If the mob using equip() has a list "equipment" and something occupying the
// objects' slot in the mob's equipment list (has something equiped in the slot
// of the item attempting to equip.)

Unequip(equipment[O.slot]) // Then we will call unequip in an attempt to remove the previously equiped object
// in the slot in question.

if(equipment && equipment[O.slot]) // Redundancy check to see if the unequip was sucessful.
return // If unequip was unsucessful return and end proc.

if(!equipment) // If the mob does not have an equipment list,
equipment = new // create a new equipment list.

equipment[O.slot] = O // Set the equipment list key for the slot in question to the object in question.

UpdateInventory() // Call UpdateInventory() updating the inventory grid.
UpdateEquipment() // Call UpdateEquipment() updating the equipment grid.


I think I have a pretty firm grasp on this, I would just like a little confirmation after being mostly inactive for a year or so. Thank you for your time.
If you have a return value for UnEquip, you don't need the redundant check.
Your understanding of the code is correct, although as Kaiochao mentioned maybe it'd be better if Unequip returned TRUE on success and FALSE on failure so you could just go:

if (!Unequip(equipment[O.slot])) return FALSE


Also maybe returning success/no success from the Equip proc is a good idea.

But both of those depend on what you want to do with everything.