ID:164387
 
In my dungeon crawler I have a proc that runs after character creation called StartingEquipment(). Basically it looks at what the variable player_class is, and gives them stuff accordingly. Broadsword for the barbarian, knives for the rogue, etc... It runs from Login().

In my obj/weapons path I have the verb Wield() which, as it implies, wields the weapon and adds stat adjustments and all that.

What I want to do is call the wield() verb after giving the player the equipment. However, I get an undefined proc error when I try and use usr.wield(). I'm assuming this is because the verb is defined under /obj/weapons, and I'm trying to access it from a proc outside of this.

Any suggestions?

- Milo

P.S: I know I'm using usr in a proc, but this game is entirely single player, so the usr is always going to be the one person playing it. Everything is working fine regardless, so I don't think it's an issue here.
"In my obj/weapons path I have the verb Wield() which, as it implies, wields the weapon and adds stat adjustments and all that."

"However, I get an undefined proc error when I try and use usr.wield()."

So Weild is defined under the weapon, but you're calling [mob].Weild? Sounds weird :). You should create the weapon, add it to the character, then call the weapon's weild proc.

mob
proc
StartingEquipment()
if(player_class=="Barbarian")
var /obj/weapon/broadsword/bs=new
bs.Move(src)
bs.Weild(src)
In response to Crashed
Thanks a lot. It's working fine now :)
In response to Milo87
Though, that's not quite how it should go. The argument to wield() is - I assume - unnecessary. Instead, when calling a verb that uses usr, you should explicitly set usr yourself.

var/obj/weapon/W = new()
usr = src
W.wield()


This will ensure that usr is set correctly. And just because there's only one player, doesn't mean it will always be that player. Take, for example, if you had something like this:

obj/boulder
density = 1
Bump(mob/M)
if(istype(M) && M.die())
else
dir = turn(dir, 90) //turn when we hit a wall or an unkillable thing
New()
..()
spawn()
while(src)
step(src, dir)
sleep(10)

mob
die()
if(client)
client.createCharacter()
else
del(src)


Obviously, all this is a bit simplified, and I wouldn't suggest using it in your game. Nevertheless, it illustrates a point: the boulder goes around crushing things. If the player didn't trigger the creation of the boulder in some way, then usr is null. If it bumps into you, then you die (usr is passed, and thus still null). When you die, character creation is called (usr is passed, and thus still null). Once you create a character, you configure its starting equipment, and call wield (usr is passed, and thus still null) and now you have a null error.

A similar error would occur with monster mobs, though I think usr would then be the mob (usr is a tricksy variable).

Point is: never ever ever ever trust usr to be what you think it should be.
In response to Garthor
Ok, thanks for the good advice :) If I ever have any errors of this kind I'll know what to look for when fixing them.