ID:167112
 
The problem is, there's a declared varible, that nothing can pick up. I was hoping someone could look at my code and suggest a possible solution. That variable is weapon.attack.

In globalmob.dm (attack code)

verb
attack(mob/m as mob in oview(1))
var d
if(equip_weapon == 1)
d = str + weapon.attack(Variable I'm having issues with)
m.damage(d)
usr<< "You did [d] damage!"
oview()<< "[usr] did [d]damage to [m]!"
m.deathcheck()
else
d = str + rand(1,4)
m.damage(d)
usr<< "You did [d] damage to [m]"
oview()<< "[usr] punches [m]!"
m.deathcheck()

In player.dm (Equip code, I've tried both the commented out lines and the non-commented lines. Both have the same result.
proc
equip(e as obj)
weapon = e
usr.attack = e.attack

// equipped_weapon -= equipped_weapon[1]
// equipped_weapon += e
// equip_weapon = 1
// weapon = equipped_weapon[1]
// usr.attack = weapon.attack

And finally, the obj declaration. (sword, under weapon.)

var attack

zodbolt
icon = 'fireball.dmi'

var value
weapon
//var attack
var hit
var damage_type

sword

damage_type = "slash"
name = "Sword of ZOD"
attack = 99
var/d = str + weapon_attack should fix all that.

Also, you've got lots of ugly code and boolean variables there. (True/False Values = if(var) or if(!var), not ==0/1)

I suggest you'd start with ZBT's RPG tutorial and after that of course the lovely and most wonderful DM Guide.
First off, I would just like to say that this is in the wrong section. This should be in Code Problems, because you have code, and there is a problem with it.

Secondly, the problem is that you are not telling us what weapon.attack is. Is this a variable that the players have?

I am going to go ahead and make some assumptions, and I am going to start off just by cleaning up your code, because it is in shambles.

mob
verb
attack(mob/m as mob in oview(1))
var/d //this just looks a lot better, and is what (I am guessing) 99% of BYOND coders are used to.
if(equip_weapon)//this is all that is needed, it is either true or it isn't. The way I have it is the same as sayinbg if(equip_weapon==1)
d = str + weapon.attack
m.damage(d) //I am going to make one of my assumptions here and say that this is a proc that you made to hurt the target.

// m.hp-=d <-- This is probably easier than referencing another proc to do the same thing.

usr<< "You did [d] damage!"
oview()<< "[usr] did [d]damage to [m]!"
m.deathcheck()
else
d = str + rand(1,4)
m.damage(d)//same as above.
usr<< "You did [d] damage to [m]"
oview()<< "[usr] punches [m] for [d] damage!" //Just assuming that you want the surrounding people to know how much damage like before.
m.deathcheck()


When playing with procs that players will be the sole users of, src should suffice just fine. If you are unsure whether or not src will be the desired target, simply add "world<<src" as the first line. That will show you who/what the src is.


The way the equip proc is set up, you would be better off making it a verb, however, you would then be able to equip any item that you have made in the game. I will show a better example at the bottom.

        proc 
equip(e as obj)
src.weapon = e //I am assuming that weapon is a variable that is pre-defined to all players mobs.
src.attack = e.attack

obj
var/attack

zodbolt
icon = 'fireball.dmi'

var/value
weapon
//var attack
var/hit
var/damage_type

sword

damage_type = "slash"
name = "Sword of ZOD"
attack = 99


That is a much better looking code in general now. As for the better way to do an equip variable:

mob
var
stradded=0//this is used in my example.
proc
equip(var/obj/O)
if(istype(O,/obj/weapon))
src.weapon=O
src.attack=O.attack
//src.str+=O.attack //this is how I would do it so you do not need to add it at every use of your weapon.
//src.stradded = O.attack //this is to keep track of what the players base strength was. src.str - src.stradded = src.originalstr
if(istype(O,/obj/armor))
//... Other stuff here for armors and shields and any other thing you may want to add.

unequip(var/obj/O)
if(istype(O,/obj/weapon))
if(src.weapon=O)//ensures you unequip the proper item.
src.weapon=new()
src.attack=new()
//src.str-=src.stradd
//src.stradd-=O.attack
if(istype(O,/obj/armor))
//... Other stuff here for anything else you wanna add.


I hope that this helps you, and that you understand what I did. If this doesn't work, you can just post and say that it didn't work, and try to give more detail when posting. If it does work, it is good to let people know, so that they don't post when you have already solved the problem.

One last thing though, I did not make any checks to see if you already have a weapon equipped or not. I am leaving that up to you to figure out how to do it. Good Luck.

p.s. I didn't go over the code too well because I am in a hurry, but it should all work fine.

§atans§pawn
In response to Satans Spawn
Thanks for the help, I know I've got a lot of ugly code, My brain is still trying to write in C++. I'm working on it. Thank you for helping a newbie. I meant to post it in code problems, just clicked the wrong link and didn't notice.

Weapon.attack is an object varible of the equipped weapon, in theory. I've got a bad habit of not clearly commenting my code, and I've rewritten it so many times.
In response to NeoKannon
C++ is *ugly*, and BYOND is only a little better. I'm in love with Scheme/LISP's syntax. <3
In response to PirateHead
Not as ugly as VB.
I saw some code for the MS Speech SDK in VB and it made me feel physically sick. How can you use such an ugly language?
I think that the same reason C++ (and other heavily structured languages) appeal to me - brackets, tabs, semicolons - everything is clear (programatically, not clear to read). Blocks? Clear start and end. Procedures? Clear start and end. Lines? Clear end. You get my point.
This is another reason BYOND is so great - use braces or semicolons, whenever you want. Got a for() loop with only two short statements? Stick em in braces and semicolon it!
Bonus points if you use that method for size-restricted challenges (4k, 8k etc).
In response to Hazman
Braces and semicolons are better than not, but in LISP-like syntax, there are only lovely parenthesis. There are few wierd "syntax quirks"; it's mostly just (procedure argument).
Ugh. That's an ugly, ugly way of doing equipment.

Use an associative list.