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

FieldMeaning
triggerWhich event earns points
criteriaOptional. Extra checks on the event's parameters
pointsPoints for each matching event
pointsModeflat (default): points per event. perAmount: points times the event's amount
intervalMsOptional. A player scores from this rule at most once per interval
descriptionOptional. Text for players that says how to earn these points
JSON
{
  "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.

TriggerCountsSet on the triggerThe event's amount
buyItemAn item the player gained and paid for with a currencyThe item's idItems gained
spendCurrencyCurrency the player spentThe currency's idAmount spent
depositCurrencyCurrency the player depositedThe currency's idAmount deposited
completionContextA context your game calledThe context's name1
dynamicTrackerA dynamic field your game set or changedThe field's keyThe value sent, when it is a number. Otherwise 1
contractInteractionAn on-chain event on a contract Stacked listens toThe contract and eventThe on-chain amount
  • On buyItem, spendCurrency and depositCurrency, amount is the least a single event must carry to count.
  • A dynamicTracker trigger can also compare the value: ==, !=, >, >=, <, <=, has, not_has, is_truthy, is_falsy or is_defined. Its key can hold a wildcard: care_action_{{x}} matches care_action_feed and care_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.

JSON
{
  "kind": "group",
  "operator": "AND",
  "conditions": [
    { "kind": "param", "param": "extra.region", "operator": "==", "value": "eu" },
    { "kind": "param", "param": "extra.clothes", "operator": "contains", "value": "itm_hat5" }
  ]
}
OperatorPasses when
==, !=The parameter equals, or does not equal, the value
>, >=, <, <=The parameter compares to the value as a number
in, not_inThe parameter is, or is not, one of the listed values
contains, not_containsA text holds the value, or a list holds it. With a list of values: all of them, or none
contains_anyThe parameter holds any of the listed values
matchesThe parameter matches a regular expression
exists, not_existsThe 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, pointsMode and intervalMs to show players how to score. It never gets the criteria.

Points and intervals

  • flat gives points for each matching event. perAmount multiplies points by the event's amount: one point per coin spent, or a score equal to the value of a field.
  • intervalMs lets a player score from the rule once per window. Windows are counted in UTC from a fixed origin, so 86400000 is 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 byWhat the points do
A live ops milestone trackAdd up toward the track's thresholds. Each track has its own rules, and points never move between tracks
A leaderboardBecome the player's score: added up, or the best or lowest single event