ID:1902300
 
Code:
mob/proc/Stam_Regen()
while(src.stam_min < src.stam_max)
sleep(50)
src.stam_min += 1
src.stam_min = src.stam_max


Problem description:
So, I am trying to create a proc that regenerates the player var stamina using 'while'. The proc is trigger by a rest command.

Regeneration works fine, but if the player stops resting, I want 'while' to stop what it's doing. I've tried a few things that don't seem to be working. How can I go about stopping 'while'? Or does it just go about it's business?

I look out the last line because you don't really need it. Assuming that loop runs until it's natural conclusion then stam_min will be equal to stam_max.

mob
var/resting = 0

verb
Toggle_Resting()
if(!resting)
resting = 1
Stam_Regen()
else
resting = 0

proc
Stam_Regen()
while(src.stam_min < src.stam_max && resting)
sleep(50)
if(!resting) break
src.stam_min += 1
mob/var/tmp/resting = 0
mob/proc/Stam_Regen()
while(src.stam_min < src.stam_max && resting)
sleep(50)
src.stam_min += 1
src.stam_min = src.stam_max
mob/verb/rest()
if(!resting)
usr.resting = 1
usr << "You're already catching Z's bro"
usr.Stam_Regen()
else
usr.resting = 0
In response to A.T.H.K
I found 'break' in the help file, but I wasn't exactly sure how to use it, now I do and knowing is half the battle.

Thanks folks.
Or that, but beware, your proc could be spawned thousands of times without that rest var check...
In response to Ham Doctor
break will leave the loop completely (breaking it)
continue will leave this current iteration of the loop and move onto the next iteration of the loop immediately from there.

Remember those 2 and you've got loops mastered.
In response to A.T.H.K
Woops yeah, added the rest check. Good point.