How to create an authoritative match using defold sdk?

Hey!

I’m trying to create an authoritative match, but I’m not sure how to do that using defold sdk.

When I search on the github the term “authoritative”, it only shows the option to list_matches, but that it’s not what I’m looking for. Code search results · GitHub

Also, on the socket.lua file, on the match_create function it only accepts the match name:

what am I missing?

thanks in advance

Hello @ropoko,

To create an authoritative match you need to register an implementation of the match handler functions and create a custom RPC to call match_create on the server. Please have a look at the authoritative multiplayer docs.

Also have a look at our tic-tac-toe authoritative example for the different runtimes.

Hope this helps.

So, seems like the lua version is pretty outdated nakama-project-template/main.lua at 50d84d8f11f7ac201f8dbcae37bc8557ae08f260 · heroiclabs/nakama-project-template · GitHub

The only function I could find is this one, that receive a whole different params:

Sorry, I’m still kinda lost on this

@ropoko you’re right, I didn’t realize the Lua example is incomplete and only registers an RPC in the project-template.

Have a look at this example for the match handlers: nakama/data/modules/match.lua at master · heroiclabs/nakama · GitHub

And here’s how the RPC to create the authoritative match is registered: nakama/data/modules/clientrpc.lua at master · heroiclabs/nakama · GitHub.

1 Like

also, just to make sure I got it, the RPC functions should be registered on server side inside the modules folder, right?

This depends on the runtime.path config, I believe the default would look into data/modules, like in the provided examples.

So in this example here, the server calls the function nk.create_match Function Reference - Heroic Labs Documentation passing the module defined on the runtime, but I was not able to find this function create_match.

The only implementation I could find is this one from socket.lua module, but I can only pass the match name instead of the module, so I don’t think it’s related to the same thing nakama-defold/nakama/socket.lua at 905c9dd0ae83393bbb31e90b024d158271f71717 · heroiclabs/nakama-defold · GitHub

If you’re looking for the nk module functions in .lua files you won’t find them, Nakama uses a Lua interpreter written in Go, you can see the match_create function here: nakama/server/runtime_lua_nakama.go at master · heroiclabs/nakama · GitHub

ooh okay, makes sense, thank you