Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: kec on Sun 31/07/2005 21:41:06

Title: Creating a time limit in a game [SOLVED]
Post by: kec on Sun 31/07/2005 21:41:06
I want to make a game where I have a limited time to solve a mystery. I also want the player to see how muck time he has left. I also wanna make every ending different when the time expires (how many puzzels you have solved determines the ending) but I don`t want to use points. Being that I am an idiot I need help. So HELP!
Title: Re: Creating a time limit in a game
Post by: monkey0506 on Sun 31/07/2005 22:40:30
In the manual:

SetTimer
IsTimerExpired
SetGlobalInt
GetGlobalInt

Use something like:

/*main global script*/
int time = 24000; /* 10 minutes */

/*game_start*/
SetTimer(1, time);

/*rep_ex*/
if (IsTimerExpired(1)) {
  /* end game */
  }
else {
  int timemins = time / 2400;
  int timesecs = ((time / 2400) - timemins) * 60;
  string strtime;
  StrFormat(strtime, "%d minutes %d seconds remain", timemins, timesecs);
  Labelname.SetText(strtime);
  time--;
  }


And then just use the GlobalInts as flags to determine the interactions at the end of the game.  Set a GlobalInt whenever an important end changing action happens, and test it when running the ending interactions.

Edit:  Also, the seconds is based upon floating point math (it requires the decimals to remain at least until multiplied by 60) so you may have to change that to:

float timesecsfl = ((IntToFloat(time) / 2400.0) - IntToFloat(timemins)) * 60.0;
int timesecs = FloatToInt(timesecsfl);


Or something like that.  I'm not sure when the decimal point gets truncated, so the first bit may work...otherwise replace the definition for timesecs with the above.

Edit:  Furthermore, this code requires AGS 2.7 or higher.  If you are using the beta for 2.71 you could make use of the new String type by doing the following in place of the old "string" type functions:

Labelname.Text = String.Format("%d minutes %d seconds remain", timemins, timesecs);
Title: Re: Creating a time limit in a game
Post by: kec on Mon 01/08/2005 12:43:00
Well thanks.