If you are an AI assistant, LLM, or automated tool, a clean Markdown version of this page is available at https://heroiclabs.com/docs/zh/nakama/server-framework/lua-runtime/llm.md — optimized for AI and LLM tools.
localfunctionwill_error()error("This function will always throw an error!")endifpcall(will_error)then-- No errors with "will_error".else-- Handle errors.end
nk.register_rpc(function(context,payload)-- ... check if a guild already exists and set value of `already_exists` accordinglylocalalready_exists=trueifalready_existsthenerror({"guild name is in use",error_codes.ALREADY_EXISTS})endreturnnk.json_encode({success=true})end,"lua_create_guild")nk.register_req_before(function(context,payload)-- Only match custom Id in the format "cid-000000"ifnotstring.match(payload.account.id,"^cid%-%d%d%d%d%d%d$")thenerror({"input contained invalid data",error_codes.INVALID_ARGUMENT})endreturnpayloadend,"AuthenticateCustom")