Basic Real Time

version 2 by Sarah Morayati

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 3 - Inform 6 Routines

    Include (-
    [ StartTimer sec ;
    time_total = sec;
    time_elapsed = timer_finished = 0;
    glk_request_timer_events(TIME_FREQUENCY); ! To keep track of time elapsed so pausing works.
    ]; -)

    Include (-
    [ SetNewTimer newsec ;
    time_total = newsec;
    time_elapsed = timer_finished = 0;
    glk_request_timer_events(TIME_FREQUENCY);
    ]; -)

    Include (-
    [ DeductFromTimer newsec ;
    time_elapsed = time_elapsed + newsec;
    glk_request_timer_events(TIME_FREQUENCY);
    ]; -)

    Include (-
    [ AddToTimer newsec ;
    time_elapsed = time_elapsed - newsec;
    glk_request_timer_events(TIME_FREQUENCY);
    ]; -)

    Include (-
    [ PauseTimer ;
    glk_request_timer_events(0);
    time_total = time_total - time_elapsed;
    ]; -)

    Include (-
    [ ResumeTimer ;
    time_elapsed = timer_finished = 0;
    glk_request_timer_events(TIME_FREQUENCY);
    ]; -)

    Include (-
    [ TimedAction ;
    switch (timer_finished) {
    0: if (time_elapsed >= time_total) timer_finished = 1; time_elapsed++;
    1: glk_request_timer_events(0); SetTimedEvent( (+ the action fires +), 1, 0);
    } ]; -)

    Include (-
    [ PrintSecondsRemaining seconds_remaining ;
    seconds_remaining = (time_total - time_elapsed) / TIME_SCALAR;
    if (seconds_remaining < 0) seconds_remaining = 0;
    print "", seconds_remaining, ""; ]; -)

    Include (-
    [ PrintSecondsElapsed seconds_elapsed ;
    seconds_elapsed = (time_elapsed) / TIME_SCALAR;
    print "", seconds_elapsed, ""; ]; -)