Streaks #

Read more about the Streaks system in Hiro here.

Functions #

List #

List all streaks and their current state and progress for a given user.

1
2
3
4
5
6
userId := "userId"

streaks, err := systems.GetStreaksSystem().List(ctx, logger, nk, userId)
if err != nil {
  return err
}

Update #

Update one or more streaks with the indicated counts for the given user.

1
2
3
4
5
6
7
userId := "userId"
streakIds := map[string]int64{"streakId_001": 5, "streakId_002": 2}

streaks, err := systems.GetStreaksSystem().Update(ctx, logger, nk, userId, streakIds)
if err != nil {
  return err
}

Claim #

Claim rewards for one or more streaks for the given user.

1
2
3
4
5
6
7
userId := "userId"
streakIds := []string{"streakId_001", "streakId_002"}

streaks, err := systems.GetStreaksSystem().Claim(ctx, logger, nk, userId, streakIds)
if err != nil {
  return err
}

Reset #

Reset progress on selected streaks for the given user.

1
2
3
4
5
6
7
userId := "userId"
streakIds := []string{"streakId_001", "streakId_002"}

streaks, err := systems.GetStreaksSystem().Reset(ctx, logger, nk, userId, streakIds)
if err != nil {
  return err
}

Hooks #

SetOnClaimReward #

Set a custom reward function which will run after a streak’s reward is rolled.

1
2
3
4
5
6
systems.GetStreaksSystem().SetOnClaimReward(OnClaimReward)

func OnClaimReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.StreaksConfigStreak, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}