Better way to update user metada?

Hi there,

Is there a better way to update user metadata than doing the way shown in docs (passing all arguments to pcall)?

(I only want to update metada for a given user)

And i’d like to know if metada is a good place to save something like ELO Ranking?

local nk = require("nakama")

local user_id = "4ec4f126-3f9d-11e7-84ef-b7c182b36521" -- some user's id.
local metadata = {}
local username = "my-new-username"
local display_name = "My new Name"
local timezone = nil
local location = "San Francisco"
local lang_tag = nil
local avatar_url = "http://graph.facebook.com/avatar_url"

local status, err = pcall(nk.account_update_id, metadata, username, display_name, timezone, location, lang_tag, avatar_url)
if (not status) then
  nk.logger_info(("Account update error: %q"):format(err))
end

Thanks

You can omit all parameters you want to leave unchanged. As the documentation for account update says you can use nil or just leave the fields out.

local nk = require("nakama")

local user_id = "4ec4f126-3f9d-11e7-84ef-b7c182b36521" -- some user's id.
local metadata = {}

local status, err = pcall(nk.account_update_id, user_id, metadata)
if (not status) then
  nk.logger_info(("Account update error: %q"):format(err))
end

That should work and do exactly what you want. Yes, storing ELO in metadata is a good idea.

1 Like