ID:1108250
 
(See the best response by LordAndrew.)
I was creating a game that would have a bunch of characters in it that all had different stats and moves, like hp,str,def,etc. but so far i've only been able to find examples of how to give all the characters the same stats. Is it possible to make all the characters have unique stats? and if so can someone show me an example or link me to where i can find one plz!!!
There are multiple ways to handle this; one way is to have a separate class for each character:

mob
character
var
health = 0
strength = 0
defense = 0

greg
health = 10
strength = 5
defense = 25

tim
health = 40
strength = 30
defense = -5


Then you would create a new instance of a character and set the client's mob to it.
I also have an attack verb defined:
        Attack()
flick("Attack",src)
for(var/mob/M in get_step(src,src.dir))
var/Damage=max(0,src.Str-M.Def)
view(M)<<"[src] hit [M] for [Damage] Damage!"
Deathcheck()

and when i use ur method of separating them into classes, i get the errors:Characters.dm:11:error: M.Def: undefined var
how do i modify the damage definition for the separation of classes?
In response to Panda dude XD
Best response
In your attack function, you're only looking for references M of the type /mob. The base /mob class does not have access to variables defined under /mob/character.

There are two ways around this:

1. Define variables (health, strength, and so on) under just the base /mob class. All descendants of /mob will then have access to them.

2. Change the for() loop within Attack() to look for /mob/character-typed references:

for(var/mob/character/m in get_step(src, dir))
world << m


For a more indepth explanation on variables, variable scope, verbs, and procedures have a look at the Guide, specifically chapters 4, 5, and 6.
oh ok, that works thx
alright it seems like my final obstacle is defining my m.Def. i've defined all the stats for all my classes but it still gives me the error in the attack verb:
        Rasengan()
flick("Rasengan",src)
for(var/mob/m in get_step(src,src.dir))
var/Damage=max(0,src-m.Def+15)
m.KnockBack(5)
view(m)<<"[src] hit [m] for [Damage] Damage!"
Deathcheck()
Flying_Thundergod_jutsu_lvl_1()
flick("Flying-Thundergod lvl1",src)
for(var/mob/m in get_step(src,src.dir))
var/Damage=max(0,src-m.Def+7)
view(m)<<"[src] hit [m] for [Damage] Damage!"

Error:Characters.dm:58:error: m.Def: undefined var
Characters.dm:65:error: m.Def: undefined var
this is the last problem im running into and im about to give up ._.
Do you have the Def variable defined for the /mob class?
I believe so, The way i did it was:
mob
character
var
HP=0
MaxHP=0
Str=0
Def=0

minato
HP=90
MaxHP=90
Str=7
Def=2

deidara
HP=100
MaxHP=100
Str=6
Def=1

grimmjow
HP=110
MaxHP=110
Str=6
Def=3

I just took ur example and applied it to my project.
In response to Panda dude XD
You have Def defined under /mob/character, but you're only looping through /mobs; see my earlier post on how to fix it.
I fixed the m.Def error, and now a new error shows up without me even changing/adding anything new.
mob
proc
Deathcheck()
if(src.HP <= 0)
view() << "[src] dies!"

Verbs.dm:9:error: src.HP: undefined var

i thought src. was universal so it wouldnt matter that i had it as src.HP but i guess not. Help plz?
In response to Panda dude XD
src points to the "container" that holds a variable or procedure. It is always the same type of whatever it is referencing; in this case src = /mob. As with the other issues you had, HP is defined under /mob/character, and the base /mob class does not have this variable.

Deathcheck() would need to be a procedure that descends from /mob/character, rather than just /mob. Again, I recommend having a look at the Guide. Chapter five explains variables and how scoping works, which is the issue you're having here.
I went to look at the guide as you suggested, and i was able to get rid of that error by making the new proc:
mob/character
proc
Deathcheck()
if(mob/character HP <= 0)
world() << "[src] has died"

but now i get the error that:
Vars.dm:4:error: HP: missing comma ',' or right-paren ')'
but i didnt see anything in the guide that would suggest me missing a comma or parenthesis....so what is it that i did wrong?
In response to Panda dude XD
if(mob/character HP <= 0) is not valid syntax in the least. That statement would never do anything but give an error.

You'd want to do something along the lines of:

mob
character
proc
deathCheck()
if(HP <= 0)
// legally dead, do death procedure stuff here
the first thing i tried was to do it your way, but i got a bunch of errors, so i changed it and came down to one error with the way i posted above so i assumed it was right. since my classes are defined under:mob/character

var
HP=0
MaxHP=0
Str=0
Def=0

minato
HP=90
MaxHP=90
Str=7
Def=2

deidara
HP=100
MaxHP=100
Str=6
Def=1

grimmjow
HP=110
MaxHP=110
Str=6
Def=3

I just added the
mob/character
proc
Deathcheck()
if(HP <= 0)
view() << "[src] has died"
in my proc file, but i still get the errors that Deathcheck proc is undefined:Characters.dm:14:error: Deathcheck: undefined proc
Characters.dm:32:error: Deathcheck: undefined proc
Characters.dm:54:error: Deathcheck: undefined proc
Characters.dm:61:error: Deathcheck: undefined proc
In response to Panda dude XD
Could you show where and how you're calling Deathcheck()?
1st attempt:
mob/character
proc
Deathcheck()
if(HP <= 0)
view() << "[src] dies!"
var
HP=0
MaxHP=0
Str=0
Def=0

minato
HP=90
MaxHP=90
Str=7
Def=2

deidara
HP=100
MaxHP=100
Str=6
Def=1

grimmjow
HP=110
MaxHP=110
Str=6
Def=3

2nd attempt:
mob/character

var
HP=0
MaxHP=0
Str=0
Def=0

minato
HP=90
MaxHP=90
Str=7
Def=2

deidara
HP=100
MaxHP=100
Str=6
Def=1

grimmjow
HP=110
MaxHP=110
Str=6
Def=3

proc
Deathcheck()
if(HP <= 0)
view() << "[src] dies!"

3rd attempt:
mob/character

var
HP=0
MaxHP=0
Str=0
Def=0

minato
HP=90
MaxHP=90
Str=7
Def=2

deidara
HP=100
MaxHP=100
Str=6
Def=1

grimmjow
HP=110
MaxHP=110
Str=6
Def=3
mob/character
proc
Deathcheck()
if(HP <= 0)
view() << "[src] dies!"

those are the three places i tried placing it in order to define the deathcheck in:
        Attack()
flick("Attack",src)
for(var/mob/character/m in get_step(src, dir))
world << m
var/Damage=max(0,src.Str-m.Def)
view(m)<<"[src] hit [m] for [Damage] Damage!"
Deathcheck()
In response to Panda dude XD
As an aside, please put your code snippets between <dm> tags. This way, the forum can apply proper formatting and syntax highlighting to them.

All three of your attempts are the same and valid. Generally it doesn't matter where you define procedures, as long as they're defined under the right "tree branch".

The issue here is that in attack, you're simply calling Deathcheck(). In the case that you're calling it, src is implied to be the one calling the procedure. Internally, it does src.Deathcheck().

What you want to do is call m.Deathcheck(). This will call Deathcheck() with m as the src.
wow. thanks alot for ur help! hopefully i wont run into anymore issues!
In response to Panda dude XD
No problem. :)