ID:2354084
 
(See the best response by GreatPirateEra.)
Code:
mob/var
Rank = 1
Exp = 0
reqExp = 100
GiveExp = 1000
isTraining = 0
showingtraining = 1

class as text
list/unlockedclasses = list("Dark Hand","Spell Slinger", "Snake Son")


Hp = 100
maxHp = 100
Str = 5
Def = 5
Mag = 5
Agi = 5

mob
player
icon = 'player.dmi'
icon_state = "Male"


mob/proc
levelCheck()
if(src.Exp >= src.reqExp)
src.Exp = src.Exp - src.reqExp //set src's exp to 0
src.reqExp = (src.reqExp*2) //set req exp to twice what it is
src.Rank += 1
src.maxHp += rand(10,50) ; src.Hp = src.maxHp
src.Str += rand (1,3)
src.Def += rand (1,3)
src.Mag += rand (1,3)
src.Agi += rand (1,3)
src.GiveExp += rand (10,50)

//raise rank
if(showingtraining == 1)
src << "You ranked up! Rank: [src.Rank]"

Problem description:

The first code is the base player code I have so far. Procs and verbs are a different dm file. The second code is my level up code. I need to know how to implement classes in the game. Should I put them in a variable as text and if so how would I go about setting specific starting stats and stat gains to each class. I'm new to coding in byond. I understand most of what I'm doing but I feel I can implement it better, some comments were made to help me remember before I got used to the program.

To be more specific. How would I make a warrior a mob with more str starting out and during leveling how would I give him more str and def .
Best response
This is way too broad a question and your snippets are irrelevant to the topic at hand. You're going to have to think this out and figure out how you want it to work, how much flexibility you require,the list goes on and on.

By the way, all those:
src.

are unnecessary. Procs default to the src who called them unless otherwise stated.

On another note, your if statement can(and should) also be simplified to
if(showingtraining)//if it's true
//if(!showingtraining) // if it's false

unless said variable can take inputs other than 0 and 1.

To give you some ideas in regards to handling classes:

You can have each class be a separate mob(and give them their own stats, techniques and whatnot), then set the client's mob to said /mob/class when choosing a class.

You can also do something like a /class datum and separate them that way, grouping them by melee/long-range/mid-range etc. Point is, you should probably think about it then write it out in pseudocode. Post it here when you've got something to show, and we'll help ya out.
Thanks for your sound advice. I had to really think about it for a while. I ended up making class a variable and setting the stats when you start on Login here

mob
Login()
if(src.LoadProc()) // since the loadproc returns 1 if there is a file, the 1 will load here
world << "[src] has Returned"
else
src.Race = input("What race do you prefer?") in list("Human")
src.Class = input("What Class do you want?") in list("Dark Hand", "Spell Slinger", "Snake Son")
if(src.Class == "Dark Hand")
src.Str = 7
src.Def = 7
src.Mag = 0
src.Agi = 6
if(src.Class == "Spell Slinger")
src.Str = 2
src.Def = 3
src.Mag = 9
src.Agi = 6
if(src.Class == "Snake Son")
src.Str = 2
src.Def= 5
src.Agi = 10
src.Mag = 3
src.loc = locate(1,1,1)
world << "[src] has Logged In"
spawn(-1) winset(src,"default","size=640x480; pos= =100,100; is-maximized = true")


And on LevelCheck() I added the condition of the class to set gain more of each classes preferred stats here.

mob/proc
levelCheck()
if(src.Exp >= src.reqExp)
src.Exp = src.Exp - src.reqExp
src.reqExp = (src.reqExp*2)
src.Rank += 1
if(src.Class == "Dark Hand")
src.maxHp += rand(20,70) ; src.Hp = src.maxHp
src.Str += rand (1,6)
src.Def += rand (1,4)
src.Mag += rand (1,3)
src.Agi += rand (1,6)
src.GiveExp += rand (10,50)

if(src.Class == "Spell Slinger")
src.maxHp += rand(10,50) ; src.Hp = src.maxHp
src.Str += rand (1,3)
src.Def += rand (1,3)
src.Mag += rand (1,13)
src.Agi += rand (1,6)
src.GiveExp += rand (10,50)

if(src.Class == "Snake Son")
src.maxHp += rand(15,55) ; src.Hp = src.maxHp
src.Str += rand (1,4)
src.Def += rand (1,4)
src.Mag += rand (1,2)
src.Agi += rand (1,10)
src.GiveExp += rand (10,50)

//raise rank
if(showingtraining)
src << "You ranked up! Rank: [src.Rank]"


It took me a while cause I put them under mob/player/var for a few hours and the rest of the code didn't work. I am reading up on datums however, cause it seems very important and the dm referece wasnt helping much.
I was thinking more along the lines of:
world
// set the mob to a temporary one on Login() to then choose our class
mob = /mob/temp

//global list/class to access later

var/list/class_list = list("fighter" = new/mob/class/fighter, "bruiser" = new/mob/class/bruiser)


/mob/class

var
//variable to identify the class?
class = null
//making stats a list for simplicity
list/stats = list(strength=1,defense=1,agility=1,endurance=1)
//stat_gains is organized in the same order ar /list/stats
list/stat_gains = list(1,1,1,1)

verb/gain_experience()
//level up the client, because why not.
client.level++
//cycle through the list of stats, and raise it by the corresponding stats defined by the class
for(var/i=1;i<=stat_gains.len, i++)
stats[i] += stat_gains[i]
client << "\blue You've leveled up!"
client <<"\green New stats: [stats[1]],[stats[2]],[stats[3]],[stats[4]]"

/mob/class/fighter
// in case you want to identify classes more easily
class = "Fighter"
//override the basic stats and stat gains for this particular class
stats = list(5,3,8,4)
stat_gains = list(5,4,3,2)


/mob/class/bruiser
class = "Bruiser"
stats = list(4,8,2,9)
stat_gains = list(2,4,1,5)


client

var
level = 1

mob/temp
Login()
..()
//pick a class from our earlier defined list
var/chosen_class = input("pick a class", "class selection") in class_list
world << " you've chosen [chosen_class]"
//set our client's mob to it
client.mob = class_list[chosen_class]
Wow, Thank you. I had no idea you could use lists that way. Never thought of stats as a list before. and definitely not the gains. It helped clean up the code a shiton, (I started a new project to start clean), however now I cant seem to get the race list to pop up, or my character to spawn in.

world
mob = /mob/temp

var/list/race_list = list("Human" = new/mob/race/Human, "Manifestation" = new/mob/race/Manifestation)
var/list/class_list = list("Iron Fist" = new/mob/class/ironFist, "Spell Slinger" = new/mob/class/spellSlinger, "Snake Son" = new/mob/class/snakeSon)

/mob/race
var
race = null

/mob/class
var
class = null

list/stats = list(Str=1,Def=1,Agi=1,Mag=1)

list/stat_gains = list(1,1,1,1)

proc/LevelUp()

client.Rank++

for(var/i=1;i<=stat_gains.len, i++)
stats[i] += stat_gains[i]

client.maxHp += rand(10,50) ; client.Hp = client.maxHp


/mob/class/ironFist
class = "Iron Fist"
stats = list(8,7,5,0)
stat_gains = list(4,3,2,1)

/mob/class/spellSlinger
class = "Spell Slinger"
stats = list(1,3,6,10)
stat_gains = list(1,2,3,4)

/mob/class/snakeSon
class = "Snake Son"
stats = list (5,3,9,3)
stat_gains = list(3,2,4,1)

/mob/race/Human
race = "Human"
icon = 'Player.dmi'
icon_state = "human"

/mob/race/Manifestation
race = "Manifestation"
icon = 'Player.dmi'
icon_state = "Manifestation"


client
var
Rank = 1
Hp = 100
maxHp = 100


mob/temp
Login()
..()

var/chosen_class = input("pick a class","Class selection") in class_list
client.mob = class_list[chosen_class]

var/chosen_race = input("Choose your Race","Race Selection") in race_list
client.mob = race_list[chosen_race]

src.loc = locate(1,1,1)
world << "[src] has Logged In"




no errors before I run but during runtime I get this

runtime error: bad client
proc name: Login (/mob/temp/Login)
usr: (src)
src: Darkstar62 (/mob/temp)
src.loc: the grass (1,1,1) (/turf/grass)
call stack:
Darkstar62 (/mob/temp): Login()
That's because your mob is being deleted as soon as you change the client mob, so it's never reaching the next step.
Ex:
/mob/temp
Login()
..()

var/chosen_race = input("Choose your Race","Race Selection") in race_list
client.mob = race_list[chosen_race]

/mob/race
Login()
..()
var/chosen_class = input("pick a class","Class selection") in class_list
client.mob = class_list[chosen_class]

/mob/class
Login()
..()
world << "[client] has logged in. His class is [class]."

This would work for what you had in mind, but is obviously something I'd recommend against.