I am currently making a minigame to play right now, (specifically a racing game) but I am unsure how to find the personal best of a player at the end of the game. I have a timer setup, but my objectives seem to make this task a little difficult? I know the scores of the times will play into this, so I will explain what I have setup with the times.
1.) I have objectives, dispsecond and dispminute.
These stand for Display Second and Display Minute. Simply, it functions as a normal timer. At the end of race, everyones' timers halt. So at the end of the race, one's score may be:
1-dispminute 39-dispsecond
Now my question still stands, how do I find the personal best?
Best Answer
Use scoreboard operations
I assume you also have the time stored in a non-formatted scoreboard, e.g. in ticks. Let's call that objective
time
. If not, see below.Make another dummy scoreboard objective called
best
, and initalize it to 0, e.g. by runningWhen a player finishes the race, mark him in some way, e.g. by assigning a tag (I'll use
tag=finished
). Then simply runThe
<
operator will assign the lesser score ofbest
andtime
tobest
. Theexecute
makes sure that both targets of the scoreboard command are the same player.You can turn
best
intobestminute
andbestsecond
the same way you convertedtime
into the display stats.Converting times to a single number
If you don't have time stored as a single continuously increasing number, you can use
scoreboard players operation
commands to turn yourdispminute
anddispseconds
scores into one. Set up the new objective, and store the number 60 in a fake player (called #SIXTY):Now, set up a repeat/chain line and run.
This will first reset the time score for every player. Then, the players' scores in
dispminutes
will be added totime
, and multiplied by 60. Lastly,dispseconds
is added to time.