wait(1) should mainly be used in loops that never become false or where the results need to be processed once each frame. To, for example, bulk-set array values with patterns, you'd use a loop without a wait. My 2D game's save/load system doesn't have this and I have one loop that runs over 7500 times, which creates a backup of a previous save file. Without the wait(1), it takes but a fraction of a second so minute, the human mind is completely unable to pick it out. If I did use it, you'd have to wait over 2 minutes for it to save the backup, let alone the actual contents which would add another 40 seconds or so. Waiting 2 1/2 minutes to save a game makes no sense, but under a millisecond does make sense. As an example, to bulk set array values with patterns, you'd have something like this:

Code:

var array_with_pattern[21];

function bulk_set_array()
{
var array_index = 0; // a temporary variable to work with the array
// breakpoint;

while(array_index < 21) // 21 is array size
{
array_with_pattern[array_index] = pow(array_index+1, 2)-1; // a pattern
array_index += 1;
}
}



Try running this code and see what happens. This is 20 loops. It's done all within one frame and you don't get the "endless loop" error (provided I didn't make a stupid mistake). You can tell if the code is running or not by simply uncommenting the breakpoint line which activates the debugger and step through it line by line. You should see it starting with 0, 1, 3, 7, 15, 31, 63, and going on clear until you see 2097151 from which the loop becomes false.

Edit: In my 2D game, if you set the time control to 2x time (press the W key), the game's back end functions run twice in one frame. At 64x time (in the full edition only), a loop is processed 64 times in one frame with a wait after it within if statements. Even with that, it's barely even registering anything in Windows Task Manager for CPU usage, 2% on average. My code is far from optimized and I have numerous cases of using my complex algorithms to work around the limits of the var.

Last edited by ulillillia; 08/07/06 14:56.

"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials