Easy place to get confused. The trick is in my next statement.
*** 3DGS is multi-tasking ***
That probably doesnt help, but I will explain.

With the your/our sample code an example it processes like this.
Its a long read, but read right through and then light will begin to shine.

1> new_box() runs through until it transfers control to i-am-dying, then PAUSES.

2> i_am_dying runs through until it hits the wait(1); statement, then WAITS UNTIL NEXT FRAME.

3> Because i_am_dying is waiting, new_box now UN-pauses and continues on.

4> new_box continues on till it FINISHES and returns control back to whatever function called it. We'll call it "Master".

5> Master will carry on until IT hits a wait(?); statement, then IT waits for next frame.

6> Other background stuff happens, during which THE NEXT FRAME STARTS.

7> Now i_am_dying has been waiting the longest so now it CONTINUES from where it was.
It decrements the counter, loops back to the while() statement and does the check. If it still has life left, it
goes into the loop, hits the wait(1); and wait for the NEXT FRAME.

8> Now control passes to the function in the "WAITing queue", which happens to be Master.

9> Master loops over and calls new_box again.

10> new_box then trundles through, creating a NEW box and a new entity to put in it.
***IMPORTANT***it created a NEW box, and it passes that box to ANOTHER COPY of i_am_dying.

11> goto step 2

Insert at 7A
7A> Now i_am_dying instance # 2 has been waiting the its turn so now it CONTINUES from where it was.
It decrements the counter, loops back to the while() statement and does the check. If it still has life left, it
goes into the loop, hits the wait(1); and wait for the NEXT FRAME.
Otherwise, like i_am_dying instance # 1 will also be doing, the counter has run out, so this
box self terminates CLOSES this COPY of the i_am_dying function. It passes control back to the "WAITing queue".

Pretty hairy stuff, but look at this, then the code, and back a few times it will make sense.
Probably.....Kind Of.......I hope.......

Ah well. Any questions, fire away.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial