Static/default matches

Hi,
How can I let the server automatically create several authoritative matches when it initiates?

Thank you,

Hello @mautoan11, you can use the CreateMatch function within InitModule to create matches when the server starts. See Server authoritative multiplayer - Heroic Labs Documentation.

Hope this helps.

Hi @sesposito, thank you for your reply.
I tried to create a default match by:
_, err := nk.MatchCreate(ctx, modulename, params)

However, I got the error:
error creating match: not found

I think you haven’t registered your match handlers. Take a look here: GitHub - heroiclabs/nakama-project-template: An example project on how to set up and write custom server code in Nakama server. for a complete example.

Hello, I am looking for the same solution, I am developing a server module with Typescript, I am sure that I’ve registered the match and tried to create default matches in “InitModule” function with correct module name, but it won’t work, the error says “error creating match: not found”, so I try to create it later by set timeout but “setTimeout is not defined”. Don’t know what I can do to create default matches properly?

Hello @insthync, could you please share a code snippet on how you’re registering and creating the match?

const InitModule: nkruntime.InitModule = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) =>
{
    initializer.registerRpc("getChannels", getChannels);
    initializer.registerMatch("default", {
        matchInit,
        matchJoinAttempt,
        matchJoin,
        matchLeave,
        matchLoop,
        matchTerminate,
        matchSignal,
    });
    // TODO: Read scene/channel list, then create match (the default one) following the list
    nk.matchCreate("default");
}

I am going to remake the server modules with Golang because the Typescript can’t store global variables, so I can’t store match Id to a global list variables.

same issue with automatically create authoritative matches when server initiates

You should avoid global state as it can create inconsistent states between the JS VMs. Although the same problem won’t apply to Go, global state is a bad practice and should be avoided. Why do you need to store the match Ids in a global when there’s a match listing function? Nakama: Query Syntax | Heroic Labs Documentation

This use case should be supported, I’ve created an issue for it: [BUG] JS registered match handlers not available within InitModule fn · Issue #849 · heroiclabs/nakama · GitHub.

1 Like

I think it is a bit more convenient for me to store match ID to the list, but never mind, I can use Query Syntax.

1 Like

Just FYI [BUG] JS registered match handlers not available within InitModule fn · Issue #849 · heroiclabs/nakama · GitHub has been resolved and will be part of the next release.

2 Likes