Skip to content
Sign upLog in
← Back to Community

Is there a way to get the highest value stored in the repl database?

Profile icon

I want to make a leaderboard for my game that displays people with the highest number of coins.

Answered by CodingElf66 [earned 5 cycles]
View Answer
Profile icon
Profile icon
Profile icon

Yes, it is possible.

scores = [] leaderboard = {} for key in db.keys(): scores.append(db[key]) highscore = max(scores) for key in db.keys(): if db[key] == highscore: leaderboard[key] = db[key] scores.pop(leaderboard[key]) highscore = max(scores)

Assuming that the key is the username, and db[key] is their highscore, then this would sort it in order.

Now you can mark it as answered, thank you!

Profile icon

Make a copy of the leader board, get the highest value and move it to a separate list. Repeat until the copy is empty, and the separate list has the scores in order.

Profile icon

When someone tries to take a look at the score, then you could get all of the values of the database and rearrange them based on score.