ID:154357
 
How do I end a proc from inside another proc?
Evilkevkev wrote:
How do I end a proc from inside another proc?

Give the second proc a return value, then test the return value in the first proc. Traditionally, 0 is used as the return value when a proc fails.

proc
proc1()
world << "in proc1 now"
var/a = 15
world << "a = [a]"
if(!proc2(a)) return
world << "back in proc1 again"
a = 35
world << "a = [a]"
if(!proc2(a)) return
world << "back in proc1 yet again."
proc2(value)
world << "in proc2 now"
if(a>30)
return 0 // fail
else
return 1 // success
when you call proc1, the text area will display:

in proc1 now
a = 15
in proc2 now
back in proc1 again
a = 35
in proc2 now

the last line "back in proc1 yet again" will not be displayed, since proc2 returned 0 and the if statement ended the proc1.
In response to Shadowdarke
if(!proc2(a)) return

How would I gauge how long the above takes to process? I have a proc that keeps time, but I want if the game ends, I want to stop it. I could guess it takes one tick, but if that's wrong then the time keeping is wrong.

In response to Evilkevkev
Evilkevkev wrote:
if(!proc2(a)) return

How would I gauge how long the above takes to process? I have a proc that keeps time, but I want if the game ends, I want to stop it. I could guess it takes one tick, but if that's wrong then the time keeping is wrong.

The best way to keep accurate time would be to store the value of world.realtime when the game begins, then subtract that from world.realtime when the game ends. A great number of factors can influence how long each tick takes, making it an extremely bad way to keep time.