Author Topic: Error Script appears to be hung  (Read 1630 times)

RickJ

  • fix'n one thing and break'n two ...
    • I can help with scripting
    • I can help with story design
    • RickJ worked on one or more games that was nominated for an AGS Award!
Error Script appears to be hung
« on: 29 Jul 2012, 03:55 »
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: Adventure Game Studio
  1. function InitModel() {
  2.         int mx, tx;
  3.  
  4.         mx = 0;
  5.         while (mx<2000) {
  6.                 // do something
  7.                 tx = 0;
  8.                 while (tx<50) {
  9.                         // do something
  10.                         tx++;
  11.                 }
  12.                 mx++;
  13.         }              
  14.         Wait(1);     // Otherwise we get a runtime error for too maany loops??
  15. }
  16.  

Calin Leafshade

  • Long live King Cat!
    • I can help with making music
    • I can help with voice acting
    • Calin Leafshade worked on one or more games that won an AGS Award!
    •  
    • Calin Leafshade worked on one or more games that was nominated for an AGS Award!
Re: Error Script appears to be hung
« Reply #1 on: 29 Jul 2012, 09:26 »
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.

Re: Error Script appears to be hung
« Reply #2 on: 29 Jul 2012, 13:07 »
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.
« Last Edit: 29 Jul 2012, 13:10 by Crimson Wizard »

RickJ

  • fix'n one thing and break'n two ...
    • I can help with scripting
    • I can help with story design
    • RickJ worked on one or more games that was nominated for an AGS Award!
Re: Error Script appears to be hung
« Reply #3 on: 29 Jul 2012, 20:40 »
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)