Best Lap in Race

Hi all,

while some progress are done in PaerVideoGame Race, I still am stuck in showing the Best Lap.

I used the www.blendenzo.com tutorial to have a script for a timer (ok), then I have a text telling me the time used for each Lap (ok, this is a variant of the above script: the timer is set to zero when a message “lap completed” is sent by the Actuator).

Now I would like to have a way to store this time lap and to show the best among each lap. Ideally it is simple, because a variable can store the time of the first lap, then if the following time lap is lower than the new value of the lap time is the second one and so on.
A Text Property can then show the value of this variable and it is done.

Unlikely it is easy to say but not to do it (at least for me).

On my own I reached this level:

I set an object to receive the Text and called it Bestlap.
Bestlap has three properties: Text=“bestlap”, timer=0, bestlaptimer=1000
When the first lap starts, nothing happens (but the timer property of the BestLap object starts to count).
When the first lap ends, a message is sent and the Logic Block of Bestlap has a sensor for this message. Then the Controller is a script like this:

own = GameLogic.getCurrentController().getOwner()


if own.timer < own.bestlaptimer:
    minutes = int(own.timer/60)
    seconds = int(own.timer%60)
    tenths = ((own.timer%60) - int(own.timer%60)) * 10
    hundredths = ((own.timer%60) - int(own.timer%60)) * 100
    laptime = str(minutes) + ":" + str("%02i"% seconds) + ":" + str(int(hundredths))
    own.bestlaptimer = own.timer
    own.Text = laptime
    
own.timer =0

Everything should work well, but the “own.timer = 0” part of the code doesn’t make the script work, because the script is active for every frame so into the if statement own.timer is 0.01 sec. instantly.

I wrote this script because I need it only once for each lap. In this way it works. I thought that the script was activated by the message only in the instant the message is sent. On the contrary, the message says to the script to start from that moment on.

So, how can I do now?

If you like to see the script in action:

http://www.papermakeit.com/index.php?option=com_docman&task=cat_view&gid=46&Itemid=70

Thank you very much! Claudio

Good news, guys!
While awaiting this post to be showed (how many posts I have to do before I can include links?), I solved my problem adding some really bad code… but now everything works fine!

Have a look at the 0.13 Release. :wink:

Bye, Claudio