Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Moox on Sun 04/04/2004 03:14:28

Title: Is there a way to implement the computers clock into ags with scripting.
Post by: Moox on Sun 04/04/2004 03:14:28
I know its possible to make timers, but i was wondering if you could implement the computers clock so at different times of day the brightness/darkness of the bgrounds changes or that new locations like a club opens. It could also be used to make an alarm clock with ags.
Title: Re:Is there a way to implement the computers clock into ags with scripting.
Post by: ElectricMonk on Sun 04/04/2004 03:38:04
Here's something I used in my upcoming game when the character looks at a clock...


{
string timebuf; //  String that will say "The time is hh:mm."
string minbuf;
string minbufpre;
string horbuf;
string horbufpre;

StrCopy(timebuf, ""); // make the text to display empty
StrCopy(minbuf, ""); // likewise the minutes...
StrCopy(minbufpre, ""); // and all else...
StrCopy(horbuf, ""); // so things won't be cluttered up with multiple text...
StrCopy(horbufpre, ""); // if you click "look" multiple times.

StrFormat(horbufpre, "%d", GetTime (1)); // read the hour into the string
if (GetTime(1) < 10) StrCat(horbuf, "0");  // prefix a 0 if necessary
StrCat(horbuf, horbufpre); // add the hour to the hour-string
StrFormat(minbufpre, "%d", GetTime (2)); // do the same for the minutes
if (GetTime(2) < 10) StrCat(minbuf, "0");
StrCat(minbuf, minbufpre);
StrCat(timebuf, "The time is  ");
StrCat(timebuf, horbuf);
StrCat(timebuf, ":");
StrCat(timebuf, minbuf);
StrCat(timebuf, ".");
Display(timebuf);   // voila!
}
Title: Re:Is there a way to implement the computers clock into ags with scripting.
Post by: Kweepa on Sun 04/04/2004 10:06:51
Here's a simpler snippet that does exactly the same thing:


string time;
StrFormat(time, "The time is %02d:%02d.", GetTime(1), GetTime(2));
Display(time);


StrFormat automatically overwrites the string, so there's no need to clear it with StrCopy. And %02d is replaced with a zero padded string representation of the number. So you could display a score in a pinball machine with %09d for example.

Cheers,
Steve
Title: Re:Is there a way to implement the computers clock into ags with scripting.
Post by: Moox on Sun 04/04/2004 15:08:31
Thanxs to both of you
Title: Re:Is there a way to implement the computers clock into ags with scripting.
Post by: ElectricMonk on Sun 04/04/2004 18:27:50
Yeah, thanks Steve.  I'm still learning...