Sign in to follow this  

Retrieving the Best Lap

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ! I'm stuck in my racing game so I need some help. I have 3 variables: LastLapMinutes, LastLapSeconds, LastLapMSeconds. This works well to retrieve the last lap (LastLap = LastLapMinutes + ":" + LastLapSeconds + ":" + LastLapMSeconds) but I can't retrieve the BestLap. I want to have a highscores table and to return the best result I can't mix integers and strings. Any help would be great ! btw I'm writing my game on Blitz3D

Share this post


Link to post
Share on other sites
Sounds like you need a few more variables :) You'll never have access to data you don't store, so create a few more variables to hold the best lap time, and replace them as necessary (that is, if you complete a lap with a better time than the old best time, then overwrite the old best time with the time from the last lap).

Share this post


Link to post
Share on other sites


int lapcount = 0;

int best_lap_time = 0;

int max_laps = 10;


FUNCTION PlayerPassesStartingLine()
IF lapcount == 0
best_lap_time = current_lap_time
END IF

lapcount++;

IF lapcount == max_laps
GameOver()
END IF
END



Or you could use a "maximum value" class, like this:




CLASS MaximumValue
PRIVATE
FLOAT TheNumber;
BOOL NoValueYet;
PUBLIC
CONSTRUCTOR ()
TheNumber = 0
NoValueYet = TRUE
END

FUNCTION ConsiderNumber(FLOAT num) AS BOOL
IF ((num > TheNumber) OR (NoValueYet))
TheNumber = num
NoValueYet = FALSE;
RETURN TRUE;
END IF

RETURN FALSE;
END

FUNCTION GetValue() AS FLOAT
RETURN TheNumber
END

FUNCTION HasValue() AS BOOL
RETURN NoValueYet
END

FUNCTION ForceValue(FLOAT value)
TheNumber = value
END
END



I'm not sure if Blitz3d has this kind of functionality, I've honestly never used or even looked at it. If it was c++ I would use something like this.

Share this post


Link to post
Share on other sites
Thanks for the replies so far ! :)

My doubt is I have LastLapMinutes, LastLapSeconds and LastLapMSeconds, when the player crosses the starting line I have the following expression:

if BestLapMinutes=<LastLapMinutes And BestLapSeconds=<LastLapSeconds And BestLapMSeconds=<LastLapMSeconds

BestLapMinute=LastLapMinutes
BestLapSeconds=LastLapSeconds
BestLapMSeconds=LastLapMSeconds

EndIf

This works fine most of the time but if for example the Last lap time is 1:50:300
and the previous best is 1:51:200 it will say it's still slower than the previous best time because BestLapMSeconds<LastLapMSeconds. :S

Share this post


Link to post
Share on other sites
Easiest solution is to convert you time variables from minutes/seconds/milli into a total of milliseconds, then its just a single comparison. You could work out the milliseconds total for the bestlap each time or save it in another variable.

e.g.


TotalLapTimeInMilliseconds = (LastLapMinutes*60*1000) + (LastLapSeconds*1000) + LastLapMSeconds

if TotalLapTimeInMilliseconds < BestLapTotalMilliseconds

BestLapTotalMilliseconds = TotalLapTimeInMilliseconds
BestLapMinute=LastLapMinutes
BestLapSeconds=LastLapSeconds
BestLapMSeconds=LastLapMSeconds

EndIf

Share this post


Link to post
Share on other sites

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this