Using pcall

@nkadd pcall is a Lua function used to trap errors.

You can use it to trap errors in function calls that you make - either your own, other libraries, or those which come from the nakama module you import. A good example is if you want to trap errors when a leaderboard is created:

local id = nk.uuid_v4()
if pcall(nk.leaderboard_create, id, "desc", "best", "0 0 * * 1", json, false) then
    nk.logger_error("failed to create leaderboard")
    -- return an error?
else
    nk.logger_info(("new leaderboard created: %q"):format(id))
end

You can have a look at our docs or the Lua manual for more examples: