View as Markdown

Stats

Read more about the Stats system in Hiro here.

Functions #

List #

List all private stats for one or more users.

1
2
3
4
5
6
userIds := []string{"userId_001", "userId_002"}

stats, err := systems.GetStatsSystem().List(ctx, logger, nk, userIds)
if err != nil {
  return err
}

Update #

Update both public and private stats for a particular player. Public and private stats are stored in different places:

  • Private stats live in the player’s storage, written with a conditional write.
  • Public stats live in the player’s account metadata.

A single Update call writes both public and private stats in one transaction.

Pass every stat you want to change in one Update call, and await each call before starting the next for a given user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
userId := "userId"
publicStats := []*hiro.StatUpdate{{
  Name:     "strength",
  Value:    1,
  Operator: hiro.StatUpdateOperator_STAT_UPDATE_OPERATOR_DELTA,
}}
privateStats := []*hiro.StatUpdate{{
  Name:     "dexterity",
  Value:    5,
  Operator: hiro.StatUpdateOperator_STAT_UPDATE_OPERATOR_SET,
}}

stats, err := systems.GetStatsSystem().Update(ctx, logger, nk, userId, publicStats, privateStats)
if err != nil {
  return err
}