- Home /
 
 
               Question by 
               Grady · Jul 03, 2011 at 04:54 AM · 
                javascripttimetiming  
              
 
              Execute code for a certain amount of time
Hey guys,
I was wondering, is it possible with javascript, to make it so that part of the code in your script will run for a couple of seconds, and then stop, but the rest of the script will run fine.....
thanks
-Grady
               Comment
              
 
               
              Answer by Eric5h5 · Jul 03, 2011 at 05:15 AM
Yes, use a coroutine. By "run for a couple of seconds", what does that mean? Do something every frame?
 function Whatever (runTime : float) {
     var timer = 0.0;
     while (timer < runTime) {
         // do something
         timer += Time.deltaTime;
         yield;
     }
 }
 
              so in the timer variable, i add how long i want the executed code to go for?
Your answer