Loop for a fixed amount of seconds

Posted By: CanadianDavid

Loop for a fixed amount of seconds - 06/24/14 04:52

Any suggestions for accurately running a while loop for a given amount of seconds without holding up the loop by using a negative wait value (ie: without using wait(-1))?
Posted By: Stansmedia

Re: Loop for a fixed amount of seconds - 06/24/14 06:38

Something like this maybe?

Code:
var number;

function wait_seconds()
{
    wait(-3);
    number = 1;
}

function mything()
{
    number = 0;
    wait_seconds();
    while(number != 1)
    {
        //do stuff
        wait(1);
    }
}

Posted By: txesmi

Re: Loop for a fixed amount of seconds - 06/24/14 08:14

Hi,
a local variable can do the same work with less code.

Code:
function fnc3secs ()
{
   var clock = total_ticks + 48; // 3 sec * 16 ticks/sec
   while ( clock > total_ticks )
   {
      wait(1);
   }
}

Posted By: oliver2s

Re: Loop for a fixed amount of seconds - 06/25/14 07:13

Code:
var timer=0; 
while(timer<3) //3 seconds
{
   timer+=time_step/16;
   wait(1);
}

© 2024 lite-C Forums