ID:2202804
 
(See the best response by Nadrew.)
like how do i code it so say if every level was 5,000xp and i gained say 30,000xp it would grant me that many levels worth instead of just 1 level up?

Best response
You'd toss it in a loop.
while(src.exp >= src.max_exp)
src.GainLevel()


Inside of GainLevel() you'd do something that adjusts either src.exp or src.max_exp in a way that allows the loop to finish.
while(xp >= mxp)
xp -= mxp
level ++
mxp = mxp * 2
mob/proc/levelup()
if(src.exp >= src.mexp)
src.exp = src.exp-src.mexp
src<<"<b><font color=blue>You leveled up!"
src.level += 1
In response to Zanoroku
Zanoroku wrote:
mob/proc/levelup()
> if(src.exp >= src.mexp)
> src.exp = src.exp-src.mexp
> src<<"<b><font color=blue>You leveled up!"
> src.level += 1


You literally didn't read the question, and you seem to be doing that a lot. If you can't provide reasonable help you shouldn't.
In response to Nadrew
Hey i'm just trying to put my opinion thats all you know it could be ignored. :/
In response to Zanoroku
Zanoroku wrote:
mob/proc/levelup()
> if(src.exp >= src.mexp)
> src.exp = src.exp-src.mexp
> src<<"<b><font color=blue>You leveled up!"
> src.level += 1


The poster wanted to know how to continue leveling if your exp exceeded the next level's exp amount too, which would be solved with a while() not an if().

src.exp = src.exp - src.mexp


should be

src.exp -= src.mexp


it's also much faster to increment by 1 via ++ than +=
In response to Kozuma3
You got a point there seems i could try and shorten some stuff so it could be more effective. Thank for the info
In response to Kozuma3
Kozuma3 wrote:
src.exp = src.exp - src.mexp

should be

src.exp -= src.mexp

it's also much faster to increment by 1 via ++ than +=


I don't mean to challenge you, but do you have proof of this. I thought that it was more of a time saver for developers than it is computing-side. I mean I personally do
x++ > x += 1 > x = x + 1

I just like to confirm that validity of your claim.
world
loop_checks = 0

mob
verb
test1()
var/x = 0
while(x<16000000)
x += 1

test2()
var/x = 0
while(x<16000000)
++x

test3()
var/x = 0
while(x<16000000)
x = x+1




test2 runs about 5% faster than test1 in my case, showing a negligible speed gain using the increment operator over the addition assignment. The increment operator should be used for iteration as a stylistic preference over addition assignments of 1. It's pretty much a standard programming-wise, and it's a decent convention.

However, x = x+1 should basically never be done. Ever. It's 33% again slower than addition assignment.

The difference between += 1 and ++ however, are negligible enough as to not really matter.

Over a small enough number of iterations, all are reasonably as fast as one another. Over a huge number of iterations, though, the difference can start to matter.

Ideally though, there's never an instance where x = x+1 is the most readable, shortest, or fastest solution and as such, even if you only change the habit for the sake of readability and in general being concise, you get the added speed bonus of using a better pattern instead. There's no benefit to using it and it's arguably a worse pattern than better alternatives by several metrics.
In response to Ter13
Thanks for taking the time to testing, explaining and replying.