Leaderboard Functions - Jamiras/RATools GitHub Wiki

leaderboard(title, description, start, cancel, submit, value, format="VALUE", lower_is_better=false, id=0, set=0)

Defines a leaderboard. title and description must be strings.

start, cancel, and submit are trigger expressions similar to the achievement's trigger parameter.

value is a memory accessor, arithmetic expression, or a function that evaluates to a memory accessor or arithmetic expression. Multiple values may be defined by encasing them in a max_of(a, b, ...) function.

format is one of the following:

  • VALUE - number (default)
  • SECS - the value is a number of seconds that should be formatted as MM:SS
  • FRAMES - the value is divided by 60 and displayed as MM:SS
  • POINTS - the value should be displayed as a zero-padded six digit number
  • MILLISECS - the value is a number of hundredths of a second and will be displayed as MM:SS.FF
  • MINUTES - the value is a number of minutes that should be formatted as HHhMM
  • SECS_AS_MINS - the value is a number of seconds that should be formatted as HHhMM
  • FLOAT1 ... FLOAT6 - the value is formatted to N digits after the decimal (FLOAT1 = 1 digit after the decimal, FLOAT3 = 3 digits after the decimal, etc).
  • FIXED1 ... FIXED3 - the value is formatted with a decimal point N spaces from the end (FIXED1 = 1 digit after the decimal).
  • TENS, HUNDREDS, THOUSANDS - the value is padded with additional 0s after the end of the value.

if lower_is_better is true, lower scores will be ranked higher in the leaderboard.

if id is provided when calling the leaderboard function, the script will generate a local leaderboard definition that the toolkit will merge into the existing leaderboard instead of putting as a separate local leaderboard.

set specifies the unique identifier of the achievement set the leaderboard should be partitioned into.

max_of(...)

Returns the highest value from a set of individual values. Usually used with measured(..., when=...) to capture different values at different times.

Can only be used within a leaderboard() value clause or rich_presence_value() expression clause.

Example

leaderboard("Fast Lap", "Get the fastest lap",
    start = complete_race(),
    submit = complete_race(),
    cancel = always_false(),
    value = max_of(
        lap_time(1),
        lap_time(2),
        lap_time(3),
        lap_time(4)
    ),
    format="MILLISECS",
    lower_is_better=true
)
leaderboard("Highest Score", "Get the highest score",
    start = start_game(),
    submit = finish_game() || game_over(),
    cancel = always_false(),
    value = max_of(
        measured(player1_score(), when=mode() == mode_single_player),
        measured(coop_score(), when=mode() == mode_coop)
    ),
    format="SCORE"