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?
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.
I'm trying to understand it. Where would this go then?
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.
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.
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)
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?
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);
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."
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);
Okay! That one got it. Thanks for your help!