Home   Help Search Login Register  

Author Topic: format["%1",_time]  (Read 450 times)

0 Members and 1 Guest are viewing this topic.

bigcheese

  • Guest
format["%1",_time]
« on: 31 Jan 2004, 22:43:03 »
Ladies,

Ive got another brainteaser for you

Im building this dialog, at the moment and I suddenly thought to myself wouldn't it be nice to have a clock in the top right corner, so I set up the command to pick up the variables  :D

Code: [Select]
format["Days  = %1 \nHours = %2 \nMinutes = %3\nSeconds = %4 \nMilliseconds = %5",_Days,_Hours,_Minutes,_Seconds,_MiSeconds]
And then I thought, hmmmmmmmm  ::) maybe I should set up some kind of script to assign these variables, so I did - or tried

It seems no matter what equations I try and do it never works properly,

So then I turned to the warming glow of the old internet, and it turns out that this very same problem has troubled many generations of code types, from the very early Hex code to Visual basic.  :-\

And now its our turn,  ;)

I would appreciate ANY relevant help on this situation, thanks.


Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:format["%1",_time]
« Reply #1 on: 31 Jan 2004, 23:29:42 »
First, what kind of time do you want to display, the current time of day, or the playing time (time since mission start)?

For the first, you can use the dayTime command which returns the time of day in hours, 14.25 --> quarter past 2 pm.

The second is given by the time command returning the game time in seconds. This command has a small glitch (or feature, depending on your viewpoint): The time is reset to zero after a save, so it actually returns time since last save.

To nicely show hours, minutes, etc. the careful use of the mod (which can be used to extract the fractional part of a number) command is necessary, e.g.

_daytime = dayTime
_mins = _daytime mod 1
_hours = _daytime - mins
_mins = _mins*60
_seconds = _mins mod 1
_mins = _mins - _seconds
_seconds = _seconds*60
_seconds = _seconds - (_seconds mod 1)

If this works as expected, _hours, _mins and _seconds should be integer number in the range 0...24,0...59,0...59 respectively.

Hope this helps,
Spinor

bigcheese

  • Guest
Re:format["%1",_time]
« Reply #2 on: 01 Feb 2004, 13:32:06 »
Worked first time Spinor

Thanks loads for your help, i wasent expecing a solution so soon,

anyway...

Thanks again