Announcement

Collapse
No announcement yet.

Timer

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

  • Timer

    Hello

    Is there a timer functionality where you start a timer and when it finishes you execute some code?

  • #2
    Hi,

    A web search of "javascript timer" or similar search terms will bring up examples.

    Here is a sample I modified from code on the web. It may provide you with a staring point.

    PHP Code:
    debugClear();
    var 
    bGotIt false;
    var 
    timerStart 0;
    var 
    vTimelimit 5;//set timer to 30 seconds
    var stopTime false;
    function 
    main() {

        var 
    timerNow;
        var 
    vTimeA = new Date();//vTimeA = the number of milliseconds since January 1, 1970 00:00:00
        
    if (bGotIt == false) {
            
    timerStart = (vTimeA)*1;
            
    bGotIt true
        }
        
    timerNow = (vTimeA)*1;
        var 
    timeLapsed = (timerNow-timerStart)/1000;
        if(
    timeLapsed vTimelimit){
            
    //place code here
            
    if(timeLapsed>0debugPrintln("timeLapsed = "+timeLapsed " Seconds");
        }else{
    //resets the timer every "vTimelimit" seconds or comment out if I just need a timer one time.
            
    if(!stopTime){
                
    debugPrintln("Total Seconds Lapsed: "+timeLapsed);
                
    stopTime true;
            }
            
    timeLapsed 0;
        }
    //        debugPrintln("timeLapsed = "+timeLapsed);

        
    return;

    Wayne

    Comment

    Working...
    X