ReferenceVerse

Leaderboard From Map

Student can sort a [player]int map and present a ranked top-N leaderboard at round end.

Updated
Watch the Knot — leaderboard-from-map in ~90 seconds.

The round ends at Fort Cannon Wall, and the top scorer's name instantly lights up on the gold billboard for the whole crew to see.

Here's how we pull scores from a map, sort them, and crown the winner.

We define a struct to hold the player and score, loop through the map to build our array, sort it, and grab the top index to update the device.

Reach for this when you need to rank players, eliminate the lowest scorers, or crown a round winner.

player_score := struct<unique>:
    Player:player
    Score:int
MyText<localizes>(S:string):message = "{S}"
leaderboard_device := class(creative_device):
    @editable GoldBoard : billboard_device = billboard_device{}
    ShowTopScores(Scores:map[player]int):void =
        var Top : []player_score = array{}
        for (P -> S := Scores):
            set Top += array{player_score{Player := P, Score := S}}
        # Sort Top array by Score descending
        if (First := Top[0]): GoldBoard.SetText(MyText("1st: {First.Score}"))

Build your own lesson with leaderboard-from-map

Generate a personalized, compile-checked lesson grounded in this exact reference.

Build a lesson →