ID:177415
 
Greetings all... I'll make this quick.

I have a character creation code that lets a player choose race, class, etc. at login :

mob
Login()
var/race=input("text","text")in list("Human",etc.)
switch(race)
if("Human")
src.magicalresistance +=1
src.dexterity -=1

(Note : Human is not the only race, I just didn't see the need to post all of them.)

var/race=input("text","text")in list("Human",etc.)

So correct me if I am wrong (I probably am, because it doesn't work), shouldn't the above line define the var "race" as whatever the player inputs? As far as I know, it should... but I get the error :

Stat.dm:9:error:race:undefined var

I get that from my statpanel code :

mob
Stat()
statpanel("Status")
stat("Race - [race]")

If you don't understand it, I apologise and I will try to make it clearer, but I have written it in a hurry.

Thanks.
you have to define it beforehand...

mob/var/race
In response to Garthor
mob/var/race is where the problem starts, I am sorry I did not mention I tried that earlier, but back on topic.

Just for example's sake, I would go :

mob/var/race="Human","Elf",etc.

With that I would get the errors :

Var.dm:5:error: ,: expected }
Var.dm:5:error: location of top-most unmatched {

That is not the only code I tried, I have added bits to the "mob/var/race" line that I think may make it work. It is basicly hit and miss because I am quite in the dark about how to fix this.

Your help is much appreciated, though.
mob/var/race //define the var race
mob
Stat()
statpanel("Status")
stat("Race","[src.race]")


mob
Login()
mob/var/list/races = list("Human","Elf",etc.)
var/class = input("What Race?","Race") in races
switch(class)
if("Human")
src.magicalresistance +=1
src.dexterity -=1
src.race = "Human"


i think thats what you want. Hope that helps.

In response to ShortyMI
just mob/var/race, not mob/var/race="Human","Elf",etc.

mob
var
race //Define the mob var 'race'
Login()
src.race = input("What race will you choose?","Select Race")in list("Human","Non-Human","DogMan")
switch(src.race)
if("Human")
src.magicalresistance +=1
src.dexterity -=1
This will set the src.race (Players Race) var to what ever they choose from the list.


The problem was you where defining a var inside the proc. Not on the mob.

mob
Stat()
statpanel("Status")
stat("Race - [src.race]")
That will check the src (The Players)



-DogMan
Others have given you correct code to go on, but just to explain why yours isn't working: You're defining var/race inside the Login() proc, so the var is good only for the duration of that proc. If the var is defined for the whole mob, not just inside the proc, like this:
mob
var/race

Login()
...
race = input(...)
...

...then this will work.
When you declare a var inside a proc it's considered a local var, and will go away at the end of the proc.

Lummox JR