Run EA every few seconds - page 2

 
yarns90401:
What does this mean? How often will the code run?

depends on the second parameter of the mathmod function\  timecurrent returns the total number of seconds since 1970 , so by finding the reminder of the division of the current time by the number of seconds you want the code to be activated at , your problem will be solved , try it , the 17 means that the code will be executed every 17 seconds
 

OR

int count =0; //defined globaly
 
 
int start()
{
if (count==5) // 5 is the number of ticks u want to skip 
{ 
 count =0;
 YOUR CODE
}
else
count++;
}
hope this is easier :)
 
yarns90401:
The idea should be to ignore the code in the start procedure if it just ran in the past n seconds. Does calling the sleep function prevent a subsequent tick move prevent the start procedure from executing?
No more than one call to start() at a time. If there is another tick coming in while current start() is still in process, the newer tick is ignored. So Sleep()-ing will ignore all those ticks.
 
old_man:
if (MathMod(TimeCurrent( ) , 17) ==0))// better to use a prime number 17,23,31 etc
 {
  YOUR CODE
 }
Nice but may not work all the time. Suppose last tick as at t=16, and because it's a slow day, the next one instead of at t=17, it comes at t=18. You'll miss one whole cycle, and may be more.
 
fireflies:
old_man:
if (MathMod(TimeCurrent( ) , 17) ==0))// better to use a prime number 17,23,31 etc
 {
  YOUR CODE
 }
Nice but may not work all the time. Suppose last tick as at t=16, and because it's a slow day, the next one instead of at t=17, it comes at t=18. You'll miss one whole cycle, and may be more.

you are right, i realized that after i had posted it.  however tthe second solution is better . note that it skip ticks not seconds
 
fireflies:

Probably you're right. But why do you want to keep a script running forever? Doesn't EA do the job?
The script doesn't have to run forever, just until stopped (just like an EA) , an the question was: "Is there a way to run an EA every n seconds?" My code does exactly this. Why would one need this? I don't know, maybe I misunderstood something.
Reason: