# Adding Bots to ELO Leaderboard

**URL:** <https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288>\
**Category:** Runtime Framework\
**Tags:** leaderboards\
**Created:** [January 21, 2022, 4:46am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288 "2022-01-21T04:46:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateek-sirah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/prateek-sirah/32/943_2.png) [@prateek-sirah](https://forum.heroiclabs.com/u/prateek-sirah)\
**Post date:** [January 21, 2022, 4:46am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/1 "2022-01-21T04:46:10Z")

</div>

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.

1. Versions: Nakama {3.7}, {Linux binary}, {Unity SDK}
2. Server Framework Runtime language {Go}

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [January 21, 2022, 8:50am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/2 "2022-01-21T08:50:28Z")

</div>

Leaderboard records don’t need to be users - they can be any characters up to [128char](https://github.com/heroiclabs/nakama/blob/master/migrate/sql/20180103142001_initial_schema.sql#L145):

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.

---

<div class="post-metadata">

**Author:** ![prateek-sirah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/prateek-sirah/32/943_2.png) [@prateek-sirah](https://forum.heroiclabs.com/u/prateek-sirah)\
**Post date:** [January 21, 2022, 11:26am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/3 "2022-01-21T11:26:18Z")

</div>

Hi @mofirouz,

The code is as follows:

```auto
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:

```auto
expects owner ID to be a valid identifier

```

I think what you are referring to might be the ID of the leaderboard itself?

> [@mofirouz](#):
>
> 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.

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?

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [January 21, 2022, 6:23pm UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/4 "2022-01-21T18:23:06Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![prateek-sirah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/prateek-sirah/32/943_2.png) [@prateek-sirah](https://forum.heroiclabs.com/u/prateek-sirah)\
**Post date:** [January 26, 2022, 5:00am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/5 "2022-01-26T05:00:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [January 26, 2022, 11:56am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/6 "2022-01-26T11:56:12Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![prateek-sirah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/prateek-sirah/32/943_2.png) [@prateek-sirah](https://forum.heroiclabs.com/u/prateek-sirah)\
**Post date:** [February 1, 2022, 5:25am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/7 "2022-02-01T05:25:53Z")

</div>

Ah I see - thanks much @mofirouz!

---

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [March 29, 2022, 8:31am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/8 "2022-03-29T08:31:25Z")

</div>

it looks like you need to create a bot as a user and use its uuid

---

<div class="post-metadata">

**Author:** ![prateek-sirah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/prateek-sirah/32/943_2.png) [@prateek-sirah](https://forum.heroiclabs.com/u/prateek-sirah)\
**Post date:** [March 29, 2022, 9:48am UTC](https://forum.heroiclabs.com/t/adding-bots-to-elo-leaderboard/2288/9 "2022-03-29T09:48:49Z")

</div>

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.](http://github.com/google/uuid)

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.
