Real time clock?

Is there some way to get the system time? I’m making a clock, and I think it would be cool to display the real time on it in game.

Umm… I’m not sure how to use that, I have pretty much no experience with python. Would there be an easy way to set the hour and minute to a property, which I could then use to control how much initial rotation the hands of the clock have?

as usual, there’s many? ways to solve the same problem!
There’s already a “time” property…
It’s a “real” clock?
You can fake one, with IPO animations, then add :
Always sensor - f:60 ( for the minutes) -> AND - Property actuator - add - nameofonepropertyhere- value:1
then select the minutes object and add:
Always Sensor -> AND - IPO Actuator - Ipo property - nameofthepropertyhere
Is this clear?

Yes this is supposed to show the real time, not just have moving hands that would look lke a real clock.

You say there’s already a time property? How do you get hours and minutes from that? Remember, games probably run at all sorts of frame rates depending on the system, so a frame based clock wouldn’t be accurate.

You have to use python for this. There’s no way to get the system time without it.

And unfortunately, you probably have to use the above mentioned script.

The trick is just to parse the returned value, which is easy in python if you know what you’re doing. Look at the post by rgrady, it should help you get exactly what you want.

I decided to come back to this for another clock I had to do (the other one I just did with a static texture, I know, boring) I learned a little python and I though I’d share the script I came up with (the example is for the second hand):

cont = GameLogic.getCurrentController()

import time

h = float(time.localtime()[3])
m = float(time.localtime()[4])
s = float(time.localtime()[5])

owner = cont.getOwner()

tempsec = owner.sec

sec = tempsec

sec = s

if tempsec > sec:
	tempsec = tempsec-60

dif = sec - tempsec

dif = dif / 60 * 6.283185

rotation = ( 0.0, 0.0, dif)

owner.applyRotation( rotation, True)

owner.sec = sec

It gets the current time, compares it to a float property which holds the last time retrieved, then figures out a value of rotation (6.283185 = 1 full rotation in radians, 2pi) which is applied only to the difference in time from the last script run (otherwise the hands go crazy) and then applies it, and then stores the current time in the float property for the next time the script is run.

I use an always sensor and python controller to run the script.

There might be a better way to do it, but that’s what I figured out myself.