How to create an in-game clock?

Started by , Thu 22/09/2005 17:32:27

Previous topic - Next topic

Khris

#20
You need to move the four declaration lines outside repeatedly_execute.
Otherwise cyclecounter will be reset to 0 every time and thus never be >= GetGameSpeed()*6.

Code: ags
// above rep_ex
int cyclecounter;
int minute;
int hour;
int ampm; //are we in the A.M. or P.M.

// inside rep_ex
  cyclecounter++;
  if (cyclecounter == (GetGameSpeed()*6)) {
    cyclecounter = 0;
    minute++;
    if (minute == 60) {
      minute = 0;
      hour++;
      if (hour == 12) ampm = 1 - ampm;
      else if (hour > 12) hour = 1;
    }
    String grrr = String.Format("The time is: %02d:%02d", hour, minute);
    if (ampm) grrr = grrr.Append(" PM");
    else grrr = grrr.Append(" AM");
    timez.Text = grrr; 
  }

SMF spam blocked by CleanTalk