Building blocks8 / 12
Scoring rules
A scoring rule turns one kind of game event into points. Live ops milestone tracks and leaderboards both score with the same rules, built in the same editor, so you learn them once.
Anatomy of a rule
| Field | Meaning |
|---|---|
trigger | Which event earns points |
criteria | Optional. Extra checks on the event's parameters |
points | Points for each matching event |
pointsMode | flat (default): points per event. perAmount: points times the event's amount |
intervalMs | Optional. A player scores from this rule at most once per interval |
description | Optional. Text for players that says how to earn these points |
{
"description": "Spend gold in the event shop",
"trigger": { "kind": "spendCurrency", "id": "currency_gold", "amount": 100 },
"points": 1,
"pointsMode": "perAmount",
"intervalMs": 86400000
}This rule gives one point per gold coin spent, for a spend of at least 100 in one go, once per day.
Triggers
A trigger names the event that counts. Each one is fed by events your game sends.
| Trigger | Counts | Set on the trigger | The event's amount |
|---|---|---|---|
buyItem | An item the player gained and paid for with a currency | The item's id | Items gained |
spendCurrency | Currency the player spent | The currency's id | Amount spent |
depositCurrency | Currency the player deposited | The currency's id | Amount deposited |
completionContext | A context your game called | The context's name | 1 |
dynamicTracker | A dynamic field your game set or changed | The field's key | The value sent, when it is a number. Otherwise 1 |
contractInteraction | An on-chain event on a contract Stacked listens to | The contract and event | The on-chain amount |
- On
buyItem,spendCurrencyanddepositCurrency,amountis the least a single event must carry to count. - A
dynamicTrackertrigger can also compare the value:==,!=,>,>=,<,<=,has,not_has,is_truthy,is_falsyoris_defined. Its key can hold a wildcard:care_action_{{x}}matchescare_action_feedandcare_action_wash. - Transfers from one player to another never score.
Criteria
Criteria look inside the event that fired. Use them when the trigger alone is too broad: only purchases in one region, only an outfit that includes one item.
A check names a parameter, an operator and a value. Checks combine in groups with AND, OR and NOT.
{
"kind": "group",
"operator": "AND",
"conditions": [
{ "kind": "param", "param": "extra.region", "operator": "==", "value": "eu" },
{ "kind": "param", "param": "extra.clothes", "operator": "contains", "value": "itm_hat5" }
]
}| Operator | Passes when |
|---|---|
==, != | The parameter equals, or does not equal, the value |
>, >=, <, <= | The parameter compares to the value as a number |
in, not_in | The parameter is, or is not, one of the listed values |
contains, not_contains | A text holds the value, or a list holds it. With a list of values: all of them, or none |
contains_any | The parameter holds any of the listed values |
matches | The parameter matches a regular expression |
exists, not_exists | The parameter is there, or is not |
param is a path into the event's parameters: extra.region, extra.clothes[0], extra.clothes.length. The SDK's own parameters are in snake case (item_id, currency_amount). What you put in extra keeps the names you gave it. event_name and user_id can be checked too.
Criteria stay on the server. Your game gets each rule's
description,trigger,points,pointsModeandintervalMsto show players how to score. It never gets the criteria.
Points and intervals
flatgivespointsfor each matching event.perAmountmultipliespointsby the event's amount: one point per coin spent, or a score equal to the value of a field.intervalMslets a player score from the rule once per window. Windows are counted in UTC from a fixed origin, so86400000is once per UTC day, not once per 24 hours since the last score.- Points are fixed when they are earned. Changing a rule changes what later events earn. Points a player already has are not worked out again.
- Scoring takes a moment. Events are processed in the background, usually within a few seconds.
Where rules are used
| Used by | What the points do |
|---|---|
| A live ops milestone track | Add up toward the track's thresholds. Each track has its own rules, and points never move between tracks |
| A leaderboard | Become the player's score: added up, or the best or lowest single event |