ID:1436817
 
(See the best response by Nadrew.)
Code:
mob
var/exp = 0
proc/GainExp(E)
if(exp < 10)
view() << "[src] gaind exp!"
usr.GainExp(5)
var/lv = 0
proc/Lv_Up(L)
if(usr.exp >= Maxexp)
lv ++
var/Maxexp = 10
proc/MaxGainE(Mex)
Maxexp = Maxexp + Mex
usr.MaxGainE(10)


Problem description:
I cant figure out why it wont lv when it hits max exp and know it wont record exp at all I should also mention that constantly sends the message saying I gained exp I made a death proc to see how it would record to the usr it works fine but every thing I throw at this doesn't work I've been at this for days and finally decided to ask for help!
You're using usr 4 times, and src 7 times, but you have 0 need for usr at all in this code.

The usr variable is a special variable that is handled contextually, so it isn't a reliable reference for the object that the procs are running on.

You should be using src because it is always 100% the object that the proc is running on (unless you manually set the src variable to something else, which you should never do anyway).


If you actually replace usr with src, you'll end up creating infinite loops because of your calls to GainExp() inside GainExp(), and MaxGainE() in MaxGainE(), which is called recursion. I'm not sure why those lines are even there.
It looks like there's a lot of mistakes going on there. It doesn't look like you're adding to the mob's exp anywhere. In your GainExp(E) proc, you're passing it a value of 5 but you're not doing anything with it, which is why you're getting stuck in a sort of endless loop. You could do:
mob
var/exp = 0
var/maxExp= 10
var/lv = 0

proc/GainExp(mob/M, var/E)// pass it the user and a value to add to the user's exp
M.exp += E
view(M) << "[M] gained exp!"
if(M.exp < 10)
GainExp(M, 5)
else // once it's 10 it'll call the lvlup proc, and passing it M which is the user mob.
Lv_Up(M)

proc/Lv_Up(mob/M)
if(M.exp >= M.Maxexp)
M.lv ++
MaxGainE(M, 10)
proc/MaxGainE(mob/M, var/Mex)
M.Maxexp += Mex
That's going to keep adding 5 exp until it gets to 10 then calling the other procs. I'm not sure exactly what it is you want here or when you were calling the other procs so I just did a quick fix. You could also do all of that in just one proc.
so then I need to replace usr with scr then right just trying to clarify?
In response to Kaiochao
I'm guessing he had the recursion in GainExp() for testing purposes, but not really sure for the other ones. And @Dark changing that would only fix one of the many problems you have going on there.
yes I have a luUp verb to test, but I decided to start over when the exp and lv stopped recording, I got an undefined proc error I came up with this this code reading the dm gide
so I kinda figured there were errors, if I take out
View() << "[M] gained exp!"<dm> it compiles but I get a run time error, how would I fix it?
In response to Dark sage biko
view(M) << "[M] gained exp!"



In response to Cubanbling
lol I see my mistake I had view capitalized.
In response to Cubanbling
well it compiles but I still get a run time error
runtime error: Cannot read 5.exp
proc name: GainExp (/mob/proc/GainExp)
usr: Dark sage biko (/mob/player)
src: Dark sage biko (/mob/player)
call stack:
Dark sage biko (/mob/player): GainExp(5, null)
Supper pop (/obj/pop): drink()<dm<
Best response
You're calling the proc wrong, it should be GainExp(player,number), which is kind of unintuitive considering the thing's already a mob proc. @Cubanbling: There's no reason to give a mob proc a mob argument unless you need to pass something besides what's calling the proc, in this case you don't; you're never interacting with anyone else but the caller of the proc.

mob
proc/GainExp(var/E)
src.exp += E
view() << "[src.name] gained exp!"
if(src.exp < 10)
src.GainExp(5)
else
src.Lv_Up()

proc/Lv_Up()
if(src.exp >= src.Maxexp)
src.lv++
src.MaxGainE(10)

proc/MaxGainE(var/Mex)
src.Maxexp += Mex


NOW you can just do 'src.GainExp(5)', which is how you'd expect things like this to function.
In response to Dark sage biko
When you call it in your verb, pass it the user then the amount. GainExp(src, 5). @Nadrew I set it up that way since at first I wasnt sure what or where he was calling the proc, it seemed like the sure fire way atm. But yeah I agree with you.
I believe this is right I got a bad argument definition?
mob
verb/GainExp()
src.GainExp(5)<dm>
I just figured it out lol thanks for all the help ^^