Skip to content

sf2.achievements

Achievements are badges the player unlocks while playing your mod. Each one is tied to a counter (see sf2.counters), so register the counter first. Register achievements while your mod loads. Get sf2 with local sf2 = require("sf2").

Create an achievement tied to one of your counters.

Signature: sf2.achievements.register { id, counter, title, description, icon, threshold, hidden? }

Parameters

Parameter Type Required
definition AchievementDefinition Required

Fields of AchievementDefinition

Field Type Required Meaning
id string Required —
counter CounterHandle Required —
title string|LocalizationHandle Required —
description string|LocalizationHandle Required —
icon string|SpriteHandle Required —
threshold integer Required —
hidden boolean Optional —

Returns: nil.

When: Entrypoint, after registering the counter.

sf2.achievements.register {
id = "first_win", counter = wins, threshold = 1,
title = sf2.text.get("achievement.first_win"),
description = sf2.text.get("achievement.first_win.description"),
icon = sf2.assets.sprite("sprites/medal"),
}

threshold must not exceed the counter’s maximum. Achievements have no reward and no unlock popup.