ID:162926
 
Does BYOND have pointers? Heres what I'm trying to do, I got this function where one parameter is a mob, and the second parameter would be the name of a variable.

When the function runs, it looks at what variable name I have supplied, and it finds that variable on the mob and uses that value.

I'm doing this because the mob has several variables on him that are references to objects being carried.

However, using this code:
    Equip(mob/Human/Player/Wearer, obj/Item, obj/Slot, var/Layer){
if(Slot == null){
Drop(Wearer);
Item.Move(Wearer);
Item.suffix = "(Equipped)";
Slot = Item;
Wearer.overlays += image(Slot.icon, icon_state = "Equipped", layer=Layer);
}
}



I can't do something like this

Equip(usr, Item, usr.BodySlot, Body_Layer);

It just doesn't work. Modifying the code however to this:

    Equip(mob/Human/Player/Wearer, obj/Item, var/Layer){
if(Wearer.BodySlot == null){
Drop(Wearer);
Item.Move(Wearer);
Item.suffix = "(Equipped)";
Wearer.BodySlot = Item;
Wearer.overlays += image(Wearer.BodySlot.icon, icon_state = "Equipped", layer=Layer);
}
}


will make it work,

but I'm not going to write a special equip function for every damn equipment slot, where the only differences would be the words like BodySlot, HeadSlot, ArmSlot, etc...


advice
I think you can achieve what you want using something like this:

proc/Equip(mob/Wearer, obj/Item, slot="BodySlot")
if(Wearer.vars.Find(slot))
Wearer.vars[slot] = Item


This will check to see if the Wearer has a variable called "BodySlot", and if it does, it will assign the item to that variable.
You could alternatively keep an associative array of equipment, so:
Equip(/mob/Human/Player/Wearer,obj/Equipment/Item,Slot)
Wearer.Equipment[Slot] = Item
//Other stuff etc etc.