How to expire a loop after predefined period of time...?

To add comments, please log in or register
Madusanka Jayaweera
131
Madusanka Jayaweera  

Please someone can help me following code......?


 int TimeNow=TimeSeconds(TimeCurrent());

   

   for (int B=0; B<5; B=B+TimeNow)

   {

///Code...........

   }


Since time has been converted to int it won't be seconds anymore I guess. How can run the loop for 4 seconds or expire after 4 seconds....?


Keith Watford
Moderator
16250
Keith Watford  

Do not double post.

I have deleted your other topic.

Anthony Garot
2774
Anthony Garot  
void OnStart()
{       
        // Get # of seconds since epoch
        int seconds = (int) TimeCurrent();              
        
        // Loop for 4 seconds
        while ( TimeCurrent() < seconds + 4 )
        {
                // Do stuff within 4 seconds
                PrintFormat("Count [%d]", TimeCurrent() - seconds);
        }
        
        // Done with 4 second loop
        Print("All done");
}
Madusanka Jayaweera
131
Madusanka Jayaweera  
Keith Watford:

Do not double post.

I have deleted your other topic.

Sorry for the inconvenience. I have tried to delete the other one. I couldn't find a option to delete it.

Madusanka Jayaweera
131
Madusanka Jayaweera  
Anthony Garot:

Thanks Anthony. Can I know one thin if I wrote a trailing SL between 4 sec it will be trailed only for 4 seconds. is it ?

Anthony Garot
2774
Anthony Garot  
Madusanka Jayaweera:

Thanks Anthony. Can I know one thin if I wrote a trailing SL between 4 sec it will be trailed only for 4 seconds. is it ?

You could build a 4 second limiter this way, but I would probably would not use a loop.

I would probably use a static variable in OnTick() to see when 4 seconds had elapsed.

It's hard to say without seeing your Trailing SL code.

Madusanka Jayaweera
131
Madusanka Jayaweera  
Anthony Garot:

You could build a 4 second limiter this way, but I would probably would not use a loop.

I would probably use a static variable in OnTick() to see when 4 seconds had elapsed.

It's hard to say without seeing your Trailing SL code.

Thanks Anthony. It's running perfectly.

To add comments, please log in or register