Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: RickJ on Sun 29/07/2012 03:55:57

Title: Error Script appears to be hung
Post by: RickJ on Sun 29/07/2012 03:55:57
If I call the following function 3 or more times I get the "infinite loop" run time error.  This code has worked previously without any problems.  Seems like the infinite loop counter ought to be reset when the function returns.  Putting in the Wait(1) instruction seems to cause the reset.  Hmmm, also putting in the explicit return also seems to trigger the reset.  In any case there needs to be something about this in the manual with regard to the while statement and the section about scripting loops.

Code (AGS) Select

function InitModel() {
int mx, tx;

mx = 0;
while (mx<2000) {
// do something
tx = 0;
while (tx<50) {
    // do something
tx++;
}
mx++;
}
Wait(1);     // Otherwise we get a runtime error for too maany loops??
}

Title: Re: Error Script appears to be hung
Post by: Calin Leafshade on Sun 29/07/2012 09:26:33
Hmm, I'm not so sure that the counter should reset on the function return since the counter is part of the call stack as a whole rather than a single function. The noloopcheck keyword can be used to circumvent issues like this though.
Title: Re: Error Script appears to be hung
Post by: Crimson Wizard on Sun 29/07/2012 13:07:59
I just checked the engine code. It looks like that the loop counter is reset only when the next main game loop iteration is run.
That means exactly that you must pass execution to the engine once in a while either by returning from event handler (not just your function), or by calling Wait.

One may say consecutive loops are counted as one. Something not elaborated in the manual well enough.
Title: Re: Error Script appears to be hung
Post by: RickJ on Sun 29/07/2012 20:40:31
Calin, Crimson,

Thanks for the info.   

Notes for manual update:

while
- check for infinite loops
- see also (noloopcheck)

noloopcheck
- check for infinite loops
- 150,000,000 loops per script execution
- reset on script completion or on wait() instruction
- see also (while, function)