ID:151150
 
I'm trying to get my experience to work, I think I'm reeeeeaaaaallllllyyyy close but it's just not working! Here's the code:
var/list/fighterLevels = list(100, 2000, 4000, 8000, 16000)

mob
var/list/expLevelList
var/exp
var/level
var/savefile="player.sav"
expLevelList
level = 1
New()
..()
src.expLevelList = 100
src << "You gained [++exp]!"

proc/AddExperience(myAmount)
exp += myAmount
if(exp >= expLevelList[level+1])
src << "You are now level [++level]!"

What's missing? Any idea's? Thanks
Gilser
On 3/5/01 10:08 pm Gilser wrote:
I'm trying to get my experience to work, I think I'm reeeeeaaaaallllllyyyy close but it's just not working! Here's the code:
var/list/fighterLevels = list(100, 2000, 4000, 8000, 16000)

mob
var/list/expLevelList
var/exp
var/level
var/savefile="player.sav"
expLevelList
level = 1
New()
..()
src.expLevelList = 100
src << "You gained [++exp]!"

proc/AddExperience(myAmount)
exp += myAmount
if(exp >= expLevelList[level+1])
src << "You are now level [++level]!"

What's missing? Any idea's? Thanks
Gilser

On the line I've bolded, the expLevelList is being set to something that's not a list. You'd have to change that to

src.expLevelList = list(100)

or

src.expLevelList = fighterLevels

(Be sure to indent it the same amount... you seem to have a lot of indentation errors! =)

Also note that once you reach the maximum level, you'll get a proc crash whenever you gain experience. You should try this (in place of its respective portion, indented to the proper depth):

proc/AddExperience(myAmount)
exp += myAmount
if(expLevelList.len >= level+1)
if(exp >= expLevelList[level+1])
src << "You are now level [++level]!"

All that does is check to see if the length of the expLevelList is greater or equal to the next level... that is, it checks to see if there is a next level attainable. If there isn't, it ensures that it won't proc crash when a person gains experience.

One final thing, is that the actual code, or did you take bits and pieces from parts of your code? Because after the line var/savefile = "player.sav", the rest is indented improperly, and the two lines below that same line are superfluous (i.e. unnecessary).
In response to Spuzzum
On the line I've bolded, the expLevelList is being set to something that's not a list. You'd have to change that to

src.expLevelList = list(100)

or

src.expLevelList = fighterLevels

(Be sure to indent it the same amount... you seem to have a lot of indentation errors! =)

Also note that once you reach the maximum level, you'll get a proc crash whenever you gain experience. You should try this (in place of its respective portion, indented to the proper depth):

proc/AddExperience(myAmount)
exp += myAmount
if(expLevelList.len >= level+1)
if(exp >= expLevelList[level+1])
src << "You are now level [++level]!"

All that does is check to see if the length of the expLevelList is greater or equal to the next level... that is, it checks to see if there is a next level attainable. If there isn't, it ensures that it won't proc crash when a person gains experience.

One final thing, is that the actual code, or did you take bits and pieces from parts of your code? Because after the line var/savefile = "player.sav", the rest is indented improperly, and the two lines below that same line are superfluous (i.e. unnecessary).


Alright, I think I got all those things corrected but...it still doesn't work! I pur in everything you said, but when i try to make these guys kill eachother, they don't get exp
Here's all the code that is in any way related to my experience:

var/list/fighterLevels = list(100, 2000, 4000, 8000, 16000)

mob
var/list/expLevelList
var/exp
var/level
var/savefile="player.sav"

New()
..()
src.expLevelList = fighterLevels
src << "You gained [++exp]!"

proc/AddExperience(myAmount)
exp += myAmount
if(expLevelList.len >= level+1)
if(exp >= expLevelList[level+1])
src << "You are now level [++level]!"


And here's what the guys look like:

mob/badguy
blob
icon = 'bigblob.dmi'
HP = 0.1
shield = 2
dexterity = 0.2
armor = 2
offense = 1.5
karma = 0
exp=100
step_mode=2
Wolf
icon = 'wolf.dmi'
HP = 1
shield = 1
dexterity = 1
armor = 2
offense = 2
karma = 0
exp=200
step_mode=2

What's wrong with this code? It compiles fine...
Thanks
Gilser
In response to Gilser
Alright, I think I got all those things corrected but...it still doesn't work! I pur in everything you said, but when i try to make these guys kill eachother, they don't get exp
Here's all the code that is in any way related to my experience:
[snip]
What's wrong with this code? It compiles fine...

Of course they don't. =)

When you kill them, you have to call AddExperience with the person who commits the deed. For example;

mob/proc/Death(mob/M) //call mob.Death(killer) to use this
M.AddExperience(src.exp) //give the killer experience
del(src) //and finish the job

So if you had a Combat() proc for when people get injured, if someone were to get killed, you would use (this is an example only, of course)

mob/proc/Combat(mob/M)
M.hp -= *blahcalculation*
if(M.hp <= 0)
M.Death(src) //kill M, with src as the killer