Hi @LoserLHM welcome
So, to add a function like what I mentioned above, isn’t it need to have a correct Lua or a go script compared to a specific version of so document and added to the modules file, then let it run.
Yes. To send inputs to the server and create your own logic to interact with it you need to write your logic in Lua or Go. These are quite different languages (and Go needs to be compiled) but it will be loaded at runtime when the server starts up.
The smallest example of a Lua script which you can put into a file and load with the server:
local nk = require("nakama")
local function custom_rpc_func(context, payload)
-- "payload" is bytes sent by the client we'll JSON decode it.
local json = nk.json_decode(payload)
You can see this code in our docs. The final line of code which calls the function
register_rpc tells the server what ID to give the function when it’s called by game clients as an RPC.
You would place the script above in a file named whatever you like (for example “script.lua”) and make sure that the server can load it via
--runtime.path <some/folder> or by default in a folder located relative to the folder where the server binary is called “data/modules”.
The code can then be called from your game client code like in the examples in our documentation:
Apparently I did something wrong making these crash but I’m kind of confused which code is a must makes a correct lua
This should not be possible. There’s no way to crash the server with your own Lua code because all code is executed in a sandbox with its own virtual machine. If you’ve got server logs it’d be good to share them so we can see what errors you see.
Hope this helps.