ID:152549
 
I was looking at your dream tutor: For the math of it article.

I was wondering why did you use while...

  proc/LevelCheck()
while(exp >= exp_next_level)
++level
exp_next_level = exp_next_level * 2 + 20
// add in stuff to gain abilities and stats here

Instead of an if statement

  proc/LevelCheck()
if(exp >= exp_next_level)
++level
exp_next_level = exp_next_level * 2 + 20
// add in stuff to gain abilities and stats here


I was wondering why you did this, is it more efficient then if? I'm sorry if this is kinda of a stupid question, but I was wondering because, I had never seen it done that way before...
He did that because the player might gain more experience than their max experience. If you used the if statement and gain more experience than your max experience, you'll have gained one level, and have more experience than your max experience.

~~> Unknown Person
In response to Unknown Person
Oh, I see. So while basically resets the var back to 0.

Also, doesn't that use a lot more cpu then an if statement? Which could cause lag with a lot of players...
In response to Broly103
Broly103 wrote:
Oh, I see. So while basically resets the var back to 0.

No, it doesn't. It just keeps on iterating the following until the condition is false, which in his case, keep leveling up the player until the player's experience is lower than their max experience.

Also, doesn't that use a lot more cpu then an if statement? Which could cause lag with a lot of players...

No, because to achive the same effect while using an if statement, the computer would be processing the same thing. Even if it did use more CPU, it would be too little to be noticable.

~~> Unknown Person
In response to Unknown Person
Unknown Person wrote:
It just keeps on iterating the following until the condition is false, which in his case, keep leveling up the player until the player's experience is lower than their max experience.

Right. In other words, by using a while loop, Lummox is allowing players to gain more than one level at a time should they gain enough experience at once to warrant it.
In response to Wizkidd0123
These are called flags btw look it up in DM via F1

mob
var/recycle=0 //this is used as a flag
var/some_other_flag=0
verb
Toggle_Some_Other_Flag()
if(!some_other_flag) some_other_flag=1
else some_other_flag=0
Recycle()
if(!recycle)
recycle=1 //turns the recycle flag on...
src<<"You start to recycle."
while(recycle) while the flag is on...do these below...
src<<"Recycling..."
if(some_other_flag) recycle=0 //if some_other_flag is on, then turn off the recycle flag
sleep(10) //sleep 1 second before going back to the start of the while loop... </dm

As written by vizuke
In response to Rickoshay
<code> Toggle_Some_Other_Flag() if(!some_other_flag) some_other_flag=1 else some_other_flag=0 </code>

The above can be simplified to:

Toggle_Some_Other_Flag()
some_other_flag = !some_other_flag