Hi!
We are using Nakama to host a 1v1 card battler where players have ELO-like ratings. We are also creating bots that will have ELO ratings which change as per their matches with players. Is there a simple way to add bots to the leaderboards in Nakama? The basic add leaderboard entry API seems to protest if a valid user ID is not provided.
- Versions: Nakama {3.7}, {Linux binary}, {Unity SDK}
- Server Framework Runtime language {Go}
Leaderboard records don’t need to be users - they can be any characters up to 128char:
What is the error that you are seeing when writing to the leaderboard?
Additionally, I’d not recommend writing leaderboard records from something that is generated like a Bot - the leaderboard records for the bot should be generated/emulated on the fly without being written to the database.
Hi @mofirouz,
The code is as follows:
if _, err := nk.LeaderboardRecordWrite(ctx, dharmaKey, bot.ID, bot.ID, int64(bot.Dharma), 0, nil, nil); err != nil {
logger.Error("Could not write bot dharma to leaderboard: %v", err)
// return "-3", fmt.Errorf("could not write bot dharma to leaderboard: %v", err)
}
and the error is:
expects owner ID to be a valid identifier
I think what you are referring to might be the ID of the leaderboard itself?
Could you please say a little bit more about why you suggest this? Our bots are going to be persistent, in that once we generate the final versions we expect them to stick around like users in the game for weeks, unless there is good reason to remove them. I wanted to add them to the leaderboard records so that I didn’t have to do a second merging of ratings and ranks. Is there a potential issue with this?
expects owner ID to be a valid identifier
What is your Bot ID that you are trying to persist? Also as you can tell the error is complaining about the OwnerID - which must be a UUID.
Could you please say a little bit more about why you suggest this? Our bots are going to be persistent, in that once we generate the final versions we expect them to stick around like users in the game for weeks, unless there is good reason to remove them. I wanted to add them to the leaderboard records so that I didn’t have to do a second merging of ratings and ranks. Is there a potential issue with this?
It doesn’t make sense to store something that is generated and is ephemeral into the database. This isn’t a problem as long as you acknowledge you are adding data to the database that can be calculated on the fly.
Hi @mofirouz
What is your Bot ID that you are trying to persist? Also as you can tell the error is complaining about the OwnerID - which must be a UUID.
The botID is a randomly generated string (using the ksuid package in golang). Is there a way to generate/turn this into a Nakama UUID?
It doesn’t make sense to store something that is generated and is ephemeral into the database. This isn’t a problem as long as you acknowledge you are adding data to the database that can be calculated on the fly.
The bots are likely to persist for a while, since we want them to essentially be pseudo-players with XP and inventory. I am storing everything else about them in a separate collection, but it would be great if the leaderboard API could sort them into the player ranked lists so that I don’t have to do that in a post-hook every time a client wants to look at the leaderboard. Hope that makes sense? Happy to hear alternate suggestions!
The botID is a randomly generated string (using the ksuid package in golang). Is there a way to generate/turn this into a Nakama UUID?
There is no “Nakama UUID” - there is just UUIDv4 that you need to pass in.
Ah I see - thanks much @mofirouz!
it looks like you need to create a bot as a user and use its uuid
Hi @tunglt1810 - no need to create a user - just assign your bot a UUID - in GoLang:
import GitHub - google/uuid: Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
and then use uuid.New().String() - I store these in a collection in the Nakama storage and use them to update the leaderboard when the bot ELO changes - it works quite well.