ID:2180404
 
(See the best response by Flame Guardian.)
Code:
mob/Stat(mob/player/M)
statpanel("[src]\s Stats") // title of the tab, shows your name, then the word stats.
stat("Name:","[usr.name]")
stat("Class:","[usr.class]")
stat("Gender:","[M.Gender]")
stat("Level:","[usr.level]")
stat("--------------------")
stat("MaxHp:","[M.HP]/[M.MAXHP]")
stat("MaxMp:","[M.MP]/[M.MAXMP]")
stat("Physical Damage:","[M.MinDmg]/[M.MaxDmg]")
stat("Magic Damage:","[M.MagicDmg]")
stat("Critical Damage:","[M.CritDmg]")
stat("Critical Rate:","[M.CritRate]%")
stat("Defense:","[M.defense]")
stat("Dodge Rate:","[M.Dodge]%")
stat("Cooldown Reduction:","[M.Cooldown]%")
stat("--------------------")
stat("Str:","[M.Str]")
stat("Int:","[M.Int]")
stat("Dex:","[M.Dex]")
stat("Sta:","[M.Sta]")
stat("Statpoints:","[M.StatPoints]")


Problem description:
This is the statpanel i created and when i have compiled the code there are no errors or warnings. But once i start the game i get a repeated runtime error:
runtime error: Cannot read null.Gender
proc name: Stat (/mob/Stat)
usr: (src)
src: Guest-3019109090 (/mob/player)
src.loc: LightGrass01 (10,9,1) (/turf/Ground/Grass/LightGrass01)
call stack:
Guest-3019109090 (/mob/player): Stat(null)

Once i del M.Gender to see if the other declared variables with M. got this they do the same thing. The statpanel also does'nt show the rest of the statpanel after classes ofcourse.

I know this is a simple problem but for some reason i'm not seeing what i've done wrong :$

Oh and the variables are defined under:
mob/player
var
Str=0
Int=0
Dex=0
Sta=0
StatPoints=10
Gender="Male"
HP=100
MAXHP=100
MP=100
MAXMP=100
defense=0
MinDmg=1
MaxDmg=5
MagicDmg=5
CritDmg=1
CritRate=1
Dodge=1
Cooldown=0
exp=0
expneeded=10
oldexp=0
expgive=0


If someone could help me with this i would be very happy ;)

Thank you in regard ^^
Best response
I haven't used stat panels since before 2008 so cut me some slack if I'm missing anything else here.

You're using M, usr and src for the same mob. This is a no-no. I don't use usr in any of my code since src does essentially the same thing and won't bring about issues.

Turn all M's and usr to src, stat(mob/M) is unnecessary.

Also your Stat() should be under player so it can pickup all the necessary variables.
mob
player
Stat()
statpanel("[src]\s Stats") // title of the tab, shows your name, then the word stats.
stat("Name:","[src.name]")


Even that may be wrong though. I could be mistaken, but I believe this might be the proper format:
mob
player
Stat()
statpanel("Stats","Name:","[src.name]")


You're also going to have to make sure your player actually is a mob/player for this to function properly.
In response to Flame Guardian
It works, thank you very much. I actually thought i had to declare them all but isee i can just use src.

To make sure the player is mob/player i used this:
world
mob = /mob/player


I suppose this is just enough right?
Of course, you said it so yourself, it's working now! haha
Oh god, now i stumble upon errors outside mob on obj procs when clicked upon, src doesnt apply there?

obj
charactercreation
Hudcreation
Frame16
icon_state="2.3"
screen_loc="5,6"
layer = MOB_LAYER+1001
Click()
usr<<sound('PressButton02.wav')
usr.class = "Thief"
src.Gender="Male"
for(var/obj/Framework/SelectionCircle/Green/GreenTopFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Green/GreenBotFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Blue/BlueTopMale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Blue/BlueBotMale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Blue/BlueTopFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Blue/BlueBotFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Red/RedTopFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Red/RedBotFemale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Red/RedTopMale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
for(var/obj/Framework/SelectionCircle/Red/RedBotMale/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
del(o)//this will delete the obj/hub's it has found on your screen
usr.client.screen += new/obj/Framework/SelectionCircle/Green/GreenTopMale
usr.client.screen += new/obj/Framework/SelectionCircle/Green/GreenBotMale


The code does'nt recognize src.Gender
src.Gender needs to be usr.Gender, src refers to the object itself.
In response to DragonDesend
With usr.Gender i get an error when i compile:

Huds.dm:517:error: usr.Gender: undefined var
Fixed it, by defining it with:

for(var/mob/player/M)
M.Gender="Male"
That would set the gender of every player in the world. You want:

if(istype(usr,/mob/player))
var/mob/player/M = usr
M.Gender = "Male"


This is called 'typecasting' it's what you do when you're sure of the type of something but it's not cast to that in the code, like instances after an istype() check.
In response to Nadrew
Because i tested in singleplayer mode i thought it worked, so i am very gratefull that you explained to me why it would'nt work in an online environment. And thank you for explaining how the istype() check works.

Everything together i learned alot today about how to define a player and a specific user, thank you ^^
In response to Flame Guardian
Interestingly, Stat() is actually intended to be usr-safe. It's a pseudo-verb like Click(), basically always called by a verb: client/Stat(). The default client/Stat() is like this:

client/Stat()
if(statobj) statobj.Stat()

However, in 99.9% of use cases for the statpanel, src and usr are identical, because pretty much no one ever changes client.statobj or calls Stat() directly. So if you're not doing those things, the code is cleaner with src.

A rare example of where usr != src might come into play is if you change client.statobj to an opponent's mob to look at their statpanel. In that case, src is going to refer to them in their Stat(), but usr will still be you. I believe Bunniflip is one of the games that does this kind of thing.