Adding Friends (Godot)

Hi Heroic Labs,

I’m trying to add friends in Godot + Nakama, and I was just wondering if it’s possible to add a friend by username alone? I’m using the “Add friends” function suggested in https://heroiclabs.com/docs/social-friends/ which hints that you can use “username” or “id”, but the add_friends_async function takes 3 arguments (session, user_id, username) and I’ve only got 2; the session and friend’s username.

Thank you!

Hi @Korama welcome :wave:

I was just wondering if it’s possible to add a friend by username alone?

Yes, the server supports the option to add users as friends by user ID or username.

the add_friends_async function takes 3 arguments (session, user_id, username) and I’ve only got 2; the session and friend’s username.

You should be able to pass in null to skip over the input. The function arguments can be seen in the client code:

https://github.com/heroiclabs/nakama-godot/blob/master/addons/com.heroiclabs.nakama/api/NakamaAPI.gd#L3453-L3458

Hope this helps.

1 Like

Thank you so much, it works now!

Although… It required some alteration of the NakamaClient.gd to accept null as an argument:

func add_friends_async(p_session : NakamaSession, p_ids : PoolStringArray, p_usernames = null) -> NakamaAsyncResult:

got changed to

func add_friends_async(p_session : NakamaSession, p_ids = null, p_usernames = null) -> NakamaAsyncResult:

and now it works. Am I missing a trick/have I broken something?

Much appreciate the help :+1:

1 Like

Am I missing a trick/have I broken something?

@Korama I’m glad you’ve solved it. I think you’ve found a limitation in the code generator used to create the NakamaClient.gd code. Please can you open an issue on the Godot client codebase and we can improve it. :slight_smile:

1 Like

It’s fixed now on the main branch, looks like it was my mistake - I was using an older version of Nakama + Godot.

Thank you.

2 Likes