Arcade-style leaderboards

Here described arcade-style leaderboards - where a single user posts multiple entries - by setting the entry’s id to a combination of the user’s ID and a current Unix time (e.g., <user-id>:<unix-time>).

But i can’t understand how to use this feature. Code:

let record = nk.leaderboardRecordWrite(FINISHING_MINI_QUEST_LEADERBOARD_ID, `${ctx.userId}:${Date.now()}`, '', 3);

throws an error expects owner ID to be a valid identifier

How can i fix this?

When creating a leaderboard entry from the server code with leaderboardRecordWrite second argument should be valid owner id. <user-id>:<unix-time> key can go to the third argument, which is doesn’t have such requirement.

third argument is username, i’ve tried user name like <user-id>:<unix-time>, but nothing changes - only one record per user

Just to clarify my understanding what you see.

  1. you are making multiple calls to leaderboardRecordWrite with same leader board id, same owner id , but differnt usernames.
  2. Then when you fetch leaderboard with leaderboardRecordsList passing same leaderboard id and owner id you get just one entry back?
  1. Yes
  2. No, i’m using nakama console
  1. leaderboardRecordsList result
{
  "nextCursor": null,
  "prevCursor": null,
  "records": [
    {
      "leaderboardId": "fishing_mini_quest",
      "ownerId": "d99ddc6b-9c0f-437a-9901-21d6bec79a0b",
      "createTime": 1660554021,
      "updateTime": 1660558921,
      "expiryTime": 1661126340,
      "rank": 1,
      "username": "d99ddc6b-9c0f-437a-9901-21d6bec79a0b:1660558921380",
      "score": 1,
      "subscore": 0,
      "numScore": 3,
      "maxNumScore": 1000000,
      "metadata": {}
    }
  ],
  "ownerRecords": [
    {
      "maxNumScore": 1000000,
      "createTime": 1660554021,
      "updateTime": 1660558921,
      "expiryTime": 1661126340,
      "score": 1,
      "subscore": 0,
      "username": "d99ddc6b-9c0f-437a-9901-21d6bec79a0b:1660558921380",
      "numScore": 3,
      "metadata": {},
      "rank": 1,
      "leaderboardId": "fishing_mini_quest",
      "ownerId": "d99ddc6b-9c0f-437a-9901-21d6bec79a0b"
    }
  ]
}

I also would like to have multiple leaderboard entries per user. I tried the suggestion about formatting the username like

<user-id>:<unix-time>

but still only get one entry. Is it actually possible to have multiple entries per ownerId?

My use case is that I have multiple players competing on the same device (all players on the same device would be using the same ownerId to submit scores). I’d like each player to see their best scores in the global rankings. I am transitioning from GameSparks where this was possible.

1 Like

I think this needs to be cleared up one-way or the other. The docs clearly state

You can implement arcade-style leaderboards - where a single user posts multiple entries - by setting the entry’s id to a combination of the user’s ID and a current Unix time (e.g., <user-id>:<unix-time> ).

See this link: Nakama: Leaderboards | Heroic Labs Documentation

This doesn’t work for me so I can only think of 3 possibilities

  1. I am doing it wrong
  2. The docs are wrong
  3. There is a bug in Nakama
1 Like

Hi, thanks for pointing this out. It is indeed an error in our documentation and we’ll remove this to avoid any further confusion.

If you still wish to implement an arcade style leaderboard you can provide any random UUIDv4 as the OwnerId value. You can then store the actual player’s user id / username in the leaderboard records meta data and when reading the records back use the value stored in metadata for display purposes instead of the owner id value.

2 Likes