I have been struggling a ton to get a basic time trial type timer that includes milliseconds.

The kicker is, I REALLY want to have my frame rate uncapped. With that in mind, this solution I found counts WAY too fast (it counts approx 30 seconds every actual second): Timers and animation frame rate

I'm thinking there may be something to using datetime, but I can't figure it out. If I could just somehow start a timer at 0, then add to it the time between the previous and current frame, I'd be golden. I just can't figure out how to do that.

EDIT: I think I am close with bge.logic.getRealTime() ...I just can't display it in the text object for some reason. I get "error return without exception set". It displays in the console just fine if I print it instead.


Turns out I've answered my own question. Here's a quick script for anyone who finds this later down the road. Just attach this to a text property and you should be good.

import bge 
from datetime import datetime

textObject = bge.logic.getCurrentController().owner 
timePassed = bge.logic.getRealTime()
timePassed = str(round(timePassed,2))
textObject.text = timePassed

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.