ID:155331
 
Alright so I am making a round based game where the hours count down, this is my code:
world
proc
GameHours()
while(global.GameInProgress)
global.hours--
global.time++
if(global.time==12)
if(global.AMPM=="AM")
global.AMPM="PM"
else
global.AMPM="AM"
if(global.time==13)
global.time=1
if(global.hours==0)
world.GameEnd()
return
world<<"<b><font color=red>It is [global.time]:00 [global.AMPM], there are currently [global.hours] hour(s) remaining until the games end.</font></b>"
sleep(100)
if(global.GameInProgress)
GameHours()
else
world<<"test"
return


Now here is the problem, even though it is a while(), it still goes through until the end. So, when the game ends, the sleep still goes. Then, it prints "test" because global.GameInProgress was set to 0. So, sometimes the first hour is very short because of this. Is there any way to externally end a separate proc?

Thank you in advance!
What do you mean? I do not understand what the problem is. Explain in detail what this code is meant to do. I understand that it is meant to keep track of the time, but not much else, let alone your problem.
In response to Xerif
Alright, let me explain a little more. What it is supposed to do is EXACTLY what you said, keep track of time. However, this is the issue. If the game ends before the time is up (for example, everyone but one person dies), then the proc will keep running until the sleep(100) ends.

In the GameEnd() proc, it sets global.GameInProgress to 0, so I thought that WOULD end the proc. However, the while will keep going until it hits the if(global.GameInProgress), AKA the sleep() ends.

Sorry that is very confusing, but basically I need a way to abruptly end the while() so it doesn't keep going, because as it is, if a new game starts before the sleep(100) ends, then the first hour will be short. Does this make sense? I explained it as best as I could.
In response to Xyphon101
You can't stop the sleep :|. What you could do is set the variable somewhere else and just leave the proc to die on its own.
In response to ExPixel
ExPixel wrote:
You can't stop the sleep :|. What you could do is set the variable somewhere else and just leave the proc to die on its own.
That is useless. The problem is when the game ends, and then someone starts it again, the first hour will be shorter. If I let the proc "die on its own" then I need to wait to start the game again.
In response to Xyphon101
I mean reset it manually by resetting all of the variables that the proc was changing. A way to make the loop stop is to set up a variable with the time at which the proc was called. If the time has been changed have the while loop stop immediately.
In response to ExPixel
ExPixel wrote:
I mean reset it manually by resetting all of the variables that the proc was changing. A way to make the loop stop is to set up a variable with the time at which the proc was called. If the time has been changed have the while loop stop immediately.
Changing the variables won't make a difference, do you understand what's happening? The time variables are being reset, HOWEVER, the sleep is still going. So, the game starts at 10 am, and lets say my sleep is 1500, so it takes 1500 milliseconds to reach 11 AM. Now let's say that the game ends at 800 milliseconds left. When the game starts again, then it will reach 11 AM after only 800 milliseconds, not 1500.

I want to STOP the while as soon as the game ends.
In response to Xyphon101
It is fixed now, thank you everyone for your support.