ID:142527
 
Code:
obj
weapons
icon = 'weapons.dmi'
Sword
icon_state = "sword"
layer = 8
item = 1
verb
Equip()
src << "<b>You equip a sword.</b>"
src.wpndmg += 1000
src.overlays += /obj/weapons/Sword
Unequip()
src << "<b>You unequip a sword.</b>"
src.wpndmg -= 1000
src.overlays += /obj/weapons/Sword


Problem description:
When I use that code, it says src.wpndmg is undefined. Yet in the attack command, when src.wpndmg is used, it works fine. What is wrong with the code?
Armiris wrote:
Code:
> obj
> weapons
> icon = 'weapons.dmi'
> Sword
> icon_state = "sword"
> layer = 8
> item = 1
> verb
> Equip()
> src << "<b>You equip a sword.</b>"
> src.wpndmg += 1000
> src.overlays += /obj/weapons/Sword
> Unequip()
> src << "<b>You unequip a sword.</b>"
> src.wpndmg -= 1000
> src.overlays += /obj/weapons/Sword
>

Problem description:
When I use that code, it says src.wpndmg is undefined. Yet in the attack command, when src.wpndmg is used, it works fine. What is wrong with the code?

In this case, the issue is that the attack command belongs to the mob, not the weapon. src is the weapon, and usr is the mob who called this verb, so that should be usr.wpndmb and usr.overlays.

Don't forget, you'll also need to keep track of which weapon is equipped, so you'll need to set usr.weapon=src when equipping, and usr.weapon=null when unequipping, plus check for cases where another weapon is already equipped (in Equip()), or the current weapon is not equipped (in Unequip()).

Lummox JR
In response to Lummox JR
Thanks.
Don't make new verbs on each object subtype (/weapon/sword/verb/Equip,/weapon/dagger/verb/Equip...), make a single set of verbs on the base type and use that (/weapon/verb/Equip). Object oriented programming isn't limited to setting just the icon for all subtypes (which incidentally might not work out for you eventually in flick()s etc).
You should never hardcode this kind of stuff (every line in your Equip() verb is 'hardcoded'!). In any case, whenever you find yourself having to duplicate code like this, you've clearly designed the system improperly.
Also, for the overlays, there is no need to use the object's type... you've got that object right there (src), so use it, just add it directly to the overlays. It is more robust so for example if your weapon there got a unique/custom (colored, or whatever) icon, etc, that one will be added. It's probably faster than adding a type path to overlays, too.