How to make my code 'wait' before executing rest of my code?

Former Member
Former Member
Hello

I am having trouble making my code wait before executing the rest of the program. The idea is that the program is supposed to overlay DataField with an alert for 5 seconds every 20 minute and then move on with the code in a loop.

Any ideas? :)
Thanks
  • You can't delay for any significant amount of time. Doing so would cause your program to be terminated for running for too long.

    You need to figure out a way to display your alert when it is supposed to be visible, and hide the alert otherwise. A primitive solution would look something like this (this code is completely untested)...

    hidden var mLastAlertTime; // time to stop showing the alert
    hidden var mNextAlertTime; // time to start showing the alert
    hidden var mAlertVisible; // indicates the alert is visible

    function compute(info)
    {
    var now = Time.now();
    if (now < mNextAlertTime) {
    mAlertVisible = true;

    // stop showing the alert 5 seconds from now
    mLastAlertTime = now.add(Gregorian.duration({ :seconds => 5 });

    // start showing the alert again 20 minutes from now
    mNextAlertTime = now.add(Gregorian.duration({ :minutes => 20 });
    }
    else if (mLastAlertTime < now) {
    mAlertVisible = false;
    }

    // any other stuff you need to do here...
    }

    function onUpdate(dc) {

    // do all of your drawing...

    if (mAlertVisible) {
    // draw the alert
    }

    }
  • Former Member
    Former Member over 10 years ago
    if((System.getTimer() % (20*60*1000)) < (5*1000)){
    // 5 second code
    }
    // optional
    else {
    // other code
    }
  • Former Member
    Former Member over 10 years ago
    if((System.getTimer() % (20*60*1000)) < (5*1000)){
    // 5 second code
    }
    // optional
    else {
    // other code
    }


    This is beautiful. Thank you! <3
    Travis thanks as well :)
  • if((System.getTimer() % (20*60*1000)) < (5*1000)){
    // 5 second code
    }
    // optional
    else {
    // other code
    }


    We need a like button. :)