Announcement

Collapse
No announcement yet.

timing procedures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • timing procedures

    Howdy folks...
    I'm having a difficult time trying to get a procedure to run once every 15 seconds and then wait for another 15 seconds to run again and have not been able to find a reliable solution....any help would be appreciated. So far I've been doing it along these lines....

    ////Premain
    function preMain( )
    {
    setPriceStudy( true );
    setColorPriceBars(true);
    var today = new Date();
    gcheckSeconds = today.getSeconds() + 15;
    }

    ///Main
    if(today.getSeconds() >= gcheckSeconds)
    {
    call procedure here
    gcheckSeconds = today.getSeconds() + 15;
    if(gcheckSeconds > 60){
    gcheckSeconds = 15;
    }
    }


    the procedure is sometimes called 2, 4, 7...maybe 15 times before it gets reset to wait 15 seconds before running again. I believe the problem to be because the script is running on ticks and not seconds, per se. Any help would be much appreciated....
    Thanks
    Chris
    Last edited by Chris747; 11-24-2004, 04:22 PM.

  • #2
    Hi Chris,

    I have not tested this, but it should work

    PHP Code:
    //outside preMain and main
    var previous_time 0;


    ////Premain
    function preMain( )
    {

    }

    ///Main
    var today = new Date();
    var 
    current_time today.getTime()/1000;
    if (
    current_time > (previous_time +15)){
        
    previous_time=current_time;
        
        
    call procedure here

    With regards to it working **exactly** at 15 second intervals, keep in mind that main will only be executed every tick. Therefore, the conditional will be true the first tick that occurs 15 seconds after it had previously been satisfied.

    Comment

    Working...
    X