sf2.counters
Counters are named numbers the game saves for your mod, such as how many times the player did something. Register a counter first, then read and change it. Get sf2 with local sf2 = require("sf2").
sf2.counters.register
Section titled “sf2.counters.register”Create a counter owned by this mod.
Signature: sf2.counters.register { id, maximum? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
CounterDefinition |
Required |
Fields of CounterDefinition
| Field | Type | Required | Meaning |
|---|---|---|---|
id |
string |
Required | — |
maximum |
integer |
Optional | — |
Returns: A counter handle.
When: Entrypoint.
local wins = sf2.counters.register { id = "wins", maximum = 1000000 }New counters start at zero.
sf2.counters.get
Section titled “sf2.counters.get”Read a counter’s saved value.
Signature: sf2.counters.get(counter)
Parameters
| Parameter | Type | Required |
|---|---|---|
counter |
CounterHandle |
Required |
Returns: The current value as a number.
When: After the profile has loaded.
local total = sf2.counters.get(wins)sf2.counters.add
Section titled “sf2.counters.add”Increase a counter. Achievements whose threshold is reached unlock.
Signature: sf2.counters.add(counter, amount)
Parameters
| Parameter | Type | Required |
|---|---|---|
counter |
CounterHandle |
Required |
amount |
integer |
Required |
Returns: The new value.
When: After the profile has loaded.
local total = sf2.counters.add(wins, 1)amount must be a non-negative whole number. The value stops at the counter’s maximum.