ID:1687853
 
(See the best response by DarkCampainger.)
Code:
#define DEBUG

obj/Inventory

proc
OnGet()//This determines what happens when the player succesfully gets src
..()

OnDrop()//This determines what happens when the player succesfully drops src
..()

//By default, all the following Allow...() procs return 1

AllowGet()//If this returns 1, then an object can be taken. If not, then it can't.
return 1

AllowDrop()//If this returns 1, then an object can be dropped. If not, then it can't.
return 1

AllowEquip()//If this returns 1, then an object can be equipped. If not, then it can't.
return 1

AllowUnequip()//If this returns 1, then an object can be unequiped. If not, then it can't.
return 1

verb

Get_Something()
set name="Get"//Set the name of the verb
set src in usr.loc
var/mob/Player/P=usr//Type Casting
P.Get(src)//Get it!!

Drop_Something()
set name="Drop"
set src in usr//Short for set src in usr.contents.
var/mob/Player/P=usr//Type Casting
P.Drop(src)//Drop it


Equipment

var
identifier//A text string that identifies the type of equipment it is.

strength//The strength bonus that a piece of equipment will give to its owner
defense//The defense bonus that a piece of equipment will give to its owner

Click()//Just to set up an alternate method of Equipping something
if(ismob(src.loc))
if(src.loc && src.loc.vars["[src.identifier]"]==src)//If src has an owner, and the owner has src equipped
src.Unequip_Something()//Unequip it

else//If it's not already equipped
src.Equip_Something()//Unequip it

verb
Equip_Something()
set name="Equip"//Set the name of the verb
set src in usr
var/mob/Player/P=usr//Type Casting
P.Equip(src)

Unequip_Something()
set name="Unequip"
set src in usr
var/mob/Player/P=usr//Type Casting
P.Unequip(src)//Unequip it

proc
OnEquip()//This determines what happens when something is equipped

OnRemoval()//We'll call this one whenever equipment is unequipped.

Top

identifier="shirt"
OnEquip()//The shield's personal action to take when it's equipped
if(istype(src.loc,/mob/Player))//Just for safety

var/mob/Player/P=loc//Type Cast

P.overlays+=src.icon

Shirt
name="Shirt"
icon='Top.dmi'
Cloak
name="Cloak"
icon='Cloak.dmi'
Tuxedo
name="Tuxedo"
icon='Tuxedo.dmi'
Fishnet
name="Fishnet Vest"
icon='Fishnet.dmi'
Leaf_Chuunin_Vest
name="Leaf Vest"
icon='LeafChuuninVest.dmi'
Sand_Chuunin_Vest
name="Sand Vest"
icon='SandChuuninVest.dmi'
Bandages
name="Bandages"
icon='Bandages.dmi'


Pants
identifier="pants"
OnEquip()//The shield's personal action to take when it's equipped
if(istype(src.loc,/mob/Player))//Just for safety

var/mob/Player/P=loc//Type Cast

P.overlays+=src.icon

Shorts
name="Pants"
icon='Noobpants.dmi'


Feet

identifier="feet"
OnEquip()//The shield's personal action to take when it's equipped
if(istype(src.loc,/mob/Player))//Just for safety

var/mob/Player/P=loc//Type Cast

P.overlays+=src.icon

Sandals
name="Sandals"
icon='Sandals.dmi'


Head
identifier="head"
OnEquip()//The shield's personal action to take when it's equipped
if(istype(src.loc,/mob/Player))//Just for safety

var/mob/Player/P=loc//Type Cast

P.overlays+=src.icon

Headband
name="Headband"
icon='Headband.dmi'


mob/Player

var
obj/Inventory/Equipment
Top/shirt//A variable to store the player's equipped weapon in. Notice that it has the same name as its identifier
Pants/pants//A variable to store the player's equipped shield in. Notice that it has the same name as its identifier
Feet/shoes//A variable to store the player's equipped shield in. Notice that it has the same name as its identifier

proc
Equip(obj/Inventory/Equipment/E)

if(!istype(E) || !E.AllowEquip() || !(E.identifier in src.vars) || src.vars["[E.identifier]"])//If it's not really an obj/Inventory/Equipment, its AllowEquip() returns 0, E's identifier isn't defined, or the player already has something of the same type equipped
return 0//Then end the current proc, doing nothing and returning 0.

E.OnEquip()
src << "You equip \a [E]."//Tell the player

src.vars["[E.identifier]"]=E//Put E into the correct category of the player's Equipment list.

E.suffix="Equipped"//atom/var/suffix represents those little blue letters that appear next to things in statpanels
E.icon+=src.overlays

Unequip(obj/Inventory/Equipment/E)

if(!istype(E) || !E.AllowUnequip() || !(E.identifier in src.vars) || src.vars["[E.identifier]"]!=E)//If E isn't equipped, E.AllowUnequip() returns 0, E's identifier isn't defined, or E isn't really a /obj/Inventory/Equipment
return 0//Then end the current proc, doing nothing and returning 0.

E.OnRemoval()
src << "You unequip your [E]."//Tell the player

src.vars["[E.identifier]"]=null//Then set the correct slot to null: They don't have one equipped anymore

E.suffix=""//atom/var/suffix represents those little blue letters that appear next to things in statpanels
E.icon-=src.overlays

Get(obj/Inventory/E)

if(istype(E) && E.AllowGet())//If it can be added to the inventory
src << "You get \a [E]!"//Tell the player.
E.Move(src)//Then add it!

E.OnGet()

Drop(obj/Inventory/Equipment/E)

if(istype(E,/obj/Inventory) && E.AllowDrop())

if(src.vars["[E.identifier]"]==E)//If E is currently equipped
Unequip(E)//Then unequip it!

src << "You drop the [E]."//Inform the player of the removal.
E.Move(locate(src.x,src.y,src.z))//Actually remove it from the player onto the turf on which the player is standing.

E.OnDrop()


The code above is from a library which I modified and then plug and played. Upon clicking the clothing, I get this RTE:

runtime error: undefined variable /mob/var/shirt
proc name: Click (/obj/Inventory/Equipment/Click)
source file: Inventory.dm,51
usr: New (/mob)
src: Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo)
call stack:
Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo): Click("Inventory", "adminpanel.info1", "icon-x=53;icon-y=17;left=1")
Kboy33 (/client): Click(Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo), "Inventory", "adminpanel.info1", "icon-x=53;icon-y=17;left=1")
Kboy33 (/client): Click(Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo), "Inventory", "adminpanel.info1", "icon-x=53;icon-y=17;left=1")


Upon right clicking and then pressing "Equip", I get the error:

runtime error: undefined proc or verb /mob/Equip().

proc name: Equip (/obj/Inventory/Equipment/verb/Equip_Something)
source file: Inventory.dm,62
usr: New (/mob)
src: Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo)
call stack:
Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo): Equip()


Finally, when trying to drop the item I receive the error:

runtime error: undefined proc or verb /mob/Drop().

proc name: Drop (/obj/Inventory/verb/Drop_Something)
source file: Inventory.dm,38
usr: New (/mob)
src: Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo)
call stack:
Tuxedo (/obj/Inventory/Equipment/Top/Tuxedo): Drop()


1) How do I fix this?
2) Are there any tips that you can give me so that I can fix RTE's by myself in the future?

Thanks a lot, all.
Best response
Your problem appears to be that your player is actually a /mob, and not a /mob/Player. Your best bet is to change world/mob to /mob/Player (and update any associated login code) so that your players are the right type.

When it comes to fixing runtime errors, all you need to do is carefully read them. Find the code file and line it refers to, and read the error description.
The description will be very specific, and take note of the paths and names it uses, as they are very exact.
It'll tell you what the usr and src were, so double-check they are what you expected.
Then, read the call stack to see how it ended up in this situation. Maybe one of the procs got a bad argument passed to it, or maybe there's an unexpected order that your code can run in.

In this case, it very clearly states that it's looking for "/mob/var/shirt" when you only have "/mob/Player/var/shirt" defined, meaning that in this line:
if(src.loc && src.loc.vars["[src.identifier]"]==src)

src.loc is actually just a /mob and not a /mob/Player.

These two posts have more information about dealing with runtime errors:
Code red - A guide to runtime errors
Dream Maker Error Code Listing
In response to DarkCampainger
Thanks! I just tackled another RTE!

Tyvm.