Author Topic: Is their any way to delay 'for' statements?  (Read 399 times)

Is their any way to delay for statements? as in, the loop, am I able to slow it down?

Don't de-rail this topic otherwise I'll just lock it.

No,

Instead use a function that calls itself with a schedule like so:


function loop(%num, %delay)
{
    //Do loop stuff

    %num--; //Decrease remaining loops by one
    if(%num < 1) //Checks if we have reached 0, then stops
         return;
    schedule(%delay, 0, loop, %num, %delay); //Calls this function after the specified delay
}
« Last Edit: October 07, 2012, 08:36:55 AM by Fluff-is-back »

No,

Instead use a function that calls itself with a schedule like so:


function loop(%num, %delay)
{
    //Do loop stuff

    %num--; //Decrease remaining loops by one
    if(%num < 1) //Checks if we have reached 0, then stops
         return;
    schedule(%delay, 0, loop, %num, %delay); //Calls this function after the specified delay
}

That's useful. Thanks laddo.

you should probably add these lines, to prevent propagation

cancel($yourSchedule);
//This goes at the beginning at your function
//It will delete any secondary loops that exist when they shouldn't


$yourSchedule = schedule(%delay,0,loop,%num,%delay);
//You need to set the schedule to a variable so that you can cancel it if needed

and by add, he means replace the bottom most line