Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: sloppy on Tue 01/11/2005 05:01:18

Title: Time display
Post by: sloppy on Tue 01/11/2005 05:01:18
Is there a way to display the correct time, but not have it in the 24-hour format?  In other words, how do you make 11:30PM show like that and not 23:30?
Title: Re: Time display
Post by: Gilbert on Tue 01/11/2005 05:13:15
Simple. Something like:

int hr;
string tmpstr;
hr=DateTime.Hour;
if (hr==12) StrFormat(tmpstr, "12:%02dp.m.", DateTime.Minute);
else if (hr==0)Ã,  StrFormat(tmpstr, "12:%02da.m.", DateTime.Minute);
else if (hr>12)Ã,  StrFormat(tmpstr, "%d:%02dp.m.", hr-12, DateTime.Minute);
elseÃ,  StrFormat(tmpstr, "%d:%02da.m.", hr, DateTime.Minute);

You can then use the tmpstr string to be displayed as a say, GUI label, or something else. Note that this is V2.7 code.
Title: Re: Time display
Post by: sloppy on Tue 01/11/2005 13:31:30
I'm trying to understand it.  Where would this go then?
Title: Re: Time display
Post by: Ashen on Tue 01/11/2005 14:27:06
Depends how & where you wanted the time displaying. If it needs to be on-screen all (or most) of the time, repeatedly_execute would be your best bet. If it's just when you look at something, the interaction script for whatever it is might be better.
See the BFAQ (http://bfaq.xylot.com/#coding03), or give us more details, for a fuller answer.
Title: Re: Time display
Post by: sloppy on Tue 01/11/2005 14:56:35
It would happen in one room.  The character looks at a clock, says the time and comments on what he's late for.  I've got that working okay, but I want normal time and not 24-hour time display.
Title: Re: Time display
Post by: Ashen on Tue 01/11/2005 15:04:32
Then just put Gilbot's script in the interaction for the clock, in place of whatever you've currently got for getting the time. (I'm guessing you've got the "It's 3:05. Damn, I'm late for a meeting!" bit sorted)
Title: Re: Time display
Post by: sloppy on Wed 02/11/2005 04:22:42
Please forgive me if I seem dense.  Do I keep this: 
DateTime *dt = DateTime.Now;
at the beginning of the interaction script? 
Then I would have this whole thing:

int hr;
string tmpstr;
hr=DateTime.Hour;
if (hr==12) StrFormat(tmpstr, "12:%02dp.m.", DateTime.Minute);
else if (hr==0)  StrFormat(tmpstr, "12:%02da.m.", DateTime.Minute);
else if (hr>12)  StrFormat(tmpstr, "%d:%02dp.m.", hr-12, DateTime.Minute);
else  StrFormat(tmpstr, "%d:%02da.m.", hr, DateTime.Minute);

What then? 
When character says - "It's ---.  I'm late for my meeting."  What do I put?  Sorry, I'm having trouble with this one.

Also, what if I want to do this in more than one room?  I would declare and then export the int and string in the global script first I suppose?
Title: Re: Time display
Post by: Gilbert on Wed 02/11/2005 04:32:53
You don't actually need that DateTime* dt... line, unless you need to keep the whole set of time somewhere.
Change the After my codes you may add something like:

StrFormat(tmpstr, "It's %s.  I'm late for my meeting.", tmpstr);
cEgo.Say(tmpstr);
Title: Re: Time display
Post by: sloppy on Wed 02/11/2005 04:59:17
Okay I did what you said. 
Now on the line that says: hr=DateTime.Hour;
I got an error message that says: "must have an instance of the struct to access a non-static member."
Title: Re: Time display
Post by: Gilbert on Wed 02/11/2005 05:06:25
Ah, seems that V2.7+ got more complicated as in the case that you MUST store the full time struct into a static location before retriving individual values. In that case the codes should be:

DateTime* dt=DateTime.Now
string tmpstr;
if (dt.Hour==12) StrFormat(tmpstr, "12:%02dp.m.", dt.Minute);
else if (dt.Hour==0)Ã,  StrFormat(tmpstr, "12:%02da.m.", dt.Minute);
else if (dt.Hour>12)Ã,  StrFormat(tmpstr, "%d:%02dp.m.", dt.Hour-12, dt.Minute);
elseÃ,  StrFormat(tmpstr, "%d:%02da.m.", dt.Hour, dt.Minute);
StrFormat(tmpstr, "It's %s.Ã,  I'm late for my meeting.", tmpstr);
cEgo.Say(tmpstr);
Title: Re: Time display
Post by: sloppy on Wed 02/11/2005 05:19:57
Okay!  That one got it.  Thanks for your help!