I'm learning programming :3
Here's a thing I made. It sorts high scores for a local leaderboard. It must follow a [[HISCORE, DATETIME, NAME], [...], [...]] format (or at least the first two items must be high score and date-time).
class LeaderboardSort:
## Sorts duplicate scores prioritizing the earlier datetime.
static func sort_duplicate_scores(a, b) -> bool:
if a[1] < b[1]:
return true
return false
## Sorts scores.
static func sort_scores(a, b) -> bool:
if a[0] > b[0]:
return true
return false
## Sorts the leaderboard array from highest to lowest score and handleds duplicate scores.
## Leaderboard array must be arranged like so: [HISCORE, int(Time.get_datetime_string_from_system(true)), "PLAYER_NAME"]
func sort_leaderboard(lb: Array) -> void:
lb.sort_custom(LeaderboardSort, "sort_duplicate_scores") # This one must be done before sort_scores()
lb.sort_custom(LeaderboardSort, "sort_scores")It worked out for me! Let me know if there are any errors.
Looking up "godot leaderboard" online yielded a whole lot of nothing. There was SilentWolf and SimpleBoards, but a whole plugin to just do high score sorting seemed over the top to me. So, I decided to try to make a high score sorter myself. Thankfully, Godot has
sort_custom() that makes it a lot simpler.No idea what "static" functions do or what separates them from regular functions, but the Editor was telling me they gotta be static. I looked it up and the explanations aren't that helpful.
#godot #gdscript #gamedev #indiedev #lambgamedev

![Function Code:
func _on_area_3d_area_entered(area: Area3D) -> void:
print (" SPIRIT COLLIDED WITH", area.get_parent().name)
var collided_item = area.get_parent()
if collided item is Gatherable:
print ("Collided with a GATHERABLE")
collided_item.do_blight()]](https://files.mastodon.social/cache/media_attachments/files/115/581/761/843/451/048/small/b61ce00ff42c2abf.png)


