Access date/time in game engine via python and 2.66 alpha shaddow issue

Hey all!

So I have two questions, first is there a way to access the current date or time with a python script?
I didnt find anything so far.
And I downloaded 2.66 and I have tested the new alpha shadows, they work but they do ‘blink’, means that about every 20th frame the alpha shadow will disappear and reappear (I also think the alpha planes change their color but I am not sure) for about 1/10 of a second.
So is there a way to fix this, or does it only work in runtime or are they aware of that bug so it will be fixed in the next release?

Thanks you for your answers :slight_smile:

you can import the time module to get time in any format you need

Thank you, it works now :slight_smile:

Here is the script (it does use a lot of propertys because I dont know how to convert an integer to a String else than using properties):


from bge import logic
import datetime


def main(cont):
    own = cont.owner
    now = datetime.datetime.now()
    
    own["second"] = now.second
    own["minute"] = now.minute
    own["hour"] = now.hour
    own["day"] = now.day
    own["month"] = now.month
    own["year"] = now.year
    
    if own["toggle"] == False:
        own["Text"] = own["hour"] + ":" + own["minute"] + ":" + own["second"]
    else:
        own["Text"] = own["month"] + "/" + own["day"] + "/" + own["year"]

And the blend is attached, you can toggle from date to time via any key!

Attachments

clock.blend (470 KB)

As you want to get a formatted string simply use the format function of str:


currentTime = datetime.datetime.now()
formattedTime = "{}:{}:{}".format(currentTime.hour, currentTime.minute, currentTime.second)
own["Text"] = formattedTime 

Thank you monster, that shortened my script a lot :slight_smile:
Also I have added some logic so seconds and minutes below 10 will be displayed as 0x (e.G. 12:04:09).
Ohh and I have fixed my issues with the alpha shaddows, they turned out to be caused by my LOD script, I have rewritten it and now it works fine!