Jibble

Author Topic: Creating a time limit in a game [SOLVED]  (Read 1418 times)

kec

  • I... nevermind
Creating a time limit in a game [SOLVED]
« on: 31 Jul 2005, 21:41 »
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!
« Last Edit: 04 Aug 2005, 18:27 by TerranRich »
I like meat.

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: Creating a time limit in a game
« Reply #1 on: 31 Jul 2005, 22:40 »
In the manual:

SetTimer
IsTimerExpired
SetGlobalInt
GetGlobalInt

Use something like:

Code: [Select]
/*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:

Code: [Select]
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:

Code: [Select]
Labelname.Text = String.Format("%d minutes %d seconds remain", timemins, timesecs);
« Last Edit: 31 Jul 2005, 22:57 by monkey_05_06 »

kec

  • I... nevermind
Re: Creating a time limit in a game
« Reply #2 on: 01 Aug 2005, 12:43 »
Well thanks.
I like meat.