# Static/default matches

**URL:** <https://forum.heroiclabs.com/t/static-default-matches/2418>\
**Category:** Runtime Framework\
**Tags:** getting-started\
**Created:** [March 2, 2022, 5:26am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418 "2022-03-02T05:26:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![mautoan11](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mautoan11](https://forum.heroiclabs.com/u/mautoan11)\
**Post date:** [March 2, 2022, 5:26am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/1 "2022-03-02T05:26:37Z")

</div>

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

Thank you,

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 2, 2022, 10:16am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/2 "2022-03-02T10:16:35Z")

</div>

Hello @mautoan11, you can use the `CreateMatch` function within `InitModule` to create matches when the server starts. See [Server authoritative multiplayer - Heroic Labs Documentation](https://heroiclabs.com/docs/nakama/concepts/server-authoritative-multiplayer/#manually).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![mautoan11](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mautoan11](https://forum.heroiclabs.com/u/mautoan11)\
**Post date:** [March 3, 2022, 3:25am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/3 "2022-03-03T03:25:47Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 3, 2022, 10:19am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/4 "2022-03-03T10:19:57Z")

</div>

> [@mautoan11](#):
>
> error creating match

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.](https://github.com/heroiclabs/nakama-project-template) for a complete example.

---

<div class="post-metadata">

**Author:** ![insthync](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/insthync/32/1135_2.png) [@insthync](https://forum.heroiclabs.com/u/insthync)\
**Post date:** [May 6, 2022, 6:13am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/5 "2022-05-06T06:13:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 6, 2022, 9:48am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/6 "2022-05-06T09:48:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![insthync](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/insthync/32/1135_2.png) [@insthync](https://forum.heroiclabs.com/u/insthync)\
**Post date:** [May 7, 2022, 7:06am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/7 "2022-05-07T07:06:36Z")

</div>

```auto
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");
}

```

---

<div class="post-metadata">

**Author:** ![insthync](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/insthync/32/1135_2.png) [@insthync](https://forum.heroiclabs.com/u/insthync)\
**Post date:** [May 7, 2022, 7:07am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/8 "2022-05-07T07:07:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![formatCvt](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/formatcvt/32/1127_2.png) [@formatCvt](https://forum.heroiclabs.com/u/formatCvt)\
**Post date:** [May 9, 2022, 12:18pm UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/9 "2022-05-09T12:18:25Z")

</div>

> [@mautoan11](#):
>
> `error creating match: not found`

same issue with automatically create authoritative matches when server initiates

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 10, 2022, 10:42am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/10 "2022-05-10T10:42:21Z")

</div>

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](https://heroiclabs.com/docs/nakama/concepts/multiplayer/query-syntax/)

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 10, 2022, 11:11am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/11 "2022-05-10T11:11:04Z")

</div>

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](https://github.com/heroiclabs/nakama/issues/849).

---

<div class="post-metadata">

**Author:** ![insthync](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/insthync/32/1135_2.png) [@insthync](https://forum.heroiclabs.com/u/insthync)\
**Post date:** [May 10, 2022, 11:58pm UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/12 "2022-05-10T23:58:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [May 19, 2022, 9:55am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/13 "2022-05-19T09:55:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lucille](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lucille](https://forum.heroiclabs.com/u/lucille)\
**Post date:** [October 23, 2024, 3:52pm UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/14 "2024-10-23T15:52:51Z")

</div>

Hi,

I’m encountering a similar issue. When I add the following code to the `InitModule`, the server halts during the Go runtime initialization:

```auto
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
	
	// Register match handler
	if err := initializer.RegisterMatch("default", func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error) {
		return &Match{}, nil
	}); err != nil {
		logger.Error("Unable to register match: %v", err)
		return err
	}

	// Create default match
	_, err := nk.MatchCreate(ctx, "default", nil)
	if err != nil {
		logger.Error("Error creating official match: %v", err)
		return err
	}

	return nil
}

```

Here is the server log:

```auto
+ /nakama/nakama migrate up --database.address root@cockroachdb:26257
{"level":"info","ts":"2024-10-23T15:57:42.614Z","caller":"server/db.go:140","msg":"Database information","version":"CockroachDB CCL v23.1.27 (x86_64-pc-linux-gnu, built 2024/10/02 05:11:25, go1.19.13)"}
{"level":"info","ts":"2024-10-23T15:57:42.615Z","caller":"migrate/migrate.go:109","msg":"Applying database migrations","limit":-1}
{"level":"info","ts":"2024-10-23T15:57:42.631Z","caller":"migrate/migrate.go:116","msg":"Successfully applied migration","count":0}
+ exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100
{"level":"warn","ts":"2024-10-23T15:57:42.680Z","caller":"server/config.go:323","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.username"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:327","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.password"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:331","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.signing_key"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:335","msg":"WARNING: insecure default parameter value, change this for production!","param":"socket.server_key"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:339","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.encryption_key"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:343","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.refresh_encryption_key"}
{"level":"warn","ts":"2024-10-23T15:57:42.681Z","caller":"server/config.go:347","msg":"WARNING: insecure default parameter value, change this for production!","param":"runtime.http_key"}
{"level":"info","ts":"2024-10-23T15:57:42.681Z","caller":"main.go:136","msg":"Nakama starting"}
{"level":"info","ts":"2024-10-23T15:57:42.681Z","caller":"main.go:137","msg":"Node","name":"nakama1","version":"3.23.0+1811efb0","runtime":"go1.22.5","cpu":4,"proc":4}
{"level":"info","ts":"2024-10-23T15:57:42.681Z","caller":"main.go:138","msg":"Data directory","path":"/nakama/data"}
{"level":"info","ts":"2024-10-23T15:57:42.681Z","caller":"main.go:149","msg":"Database connections","dsns":["root@cockroachdb:26257"]}
{"level":"debug","ts":"2024-10-23T15:57:42.683Z","caller":"server/db.go:116","msg":"Complete database connection URL","raw_url":"postgres://root@cockroachdb:26257/nakama?sslmode=prefer"}
{"level":"info","ts":"2024-10-23T15:57:42.694Z","caller":"server/db.go:140","msg":"Database information","version":"CockroachDB CCL v23.1.27 (x86_64-pc-linux-gnu, built 2024/10/02 05:11:25, go1.19.13)"}
{"level":"info","ts":"2024-10-23T15:57:42.713Z","caller":"server/metrics.go:178","msg":"Starting Prometheus server for metrics requests","port":9100}
{"level":"info","ts":"2024-10-23T15:57:42.732Z","caller":"server/leaderboard_rank_cache.go:140","msg":"Initializing leaderboard rank cache"}
{"level":"info","ts":"2024-10-23T15:57:42.732Z","caller":"server/leaderboard_rank_cache.go:201","msg":"Leaderboard rank cache initialization completed successfully","cached":[],"skipped":[],"duration":"235.189µs"}
{"level":"info","ts":"2024-10-23T15:57:42.734Z","caller":"server/runtime.go:646","msg":"Initialising runtime","path":"/nakama/data/modules"}
{"level":"info","ts":"2024-10-23T15:57:42.734Z","caller":"server/runtime.go:653","msg":"Initialising runtime event queue processor"}
{"level":"info","ts":"2024-10-23T15:57:42.734Z","caller":"server/runtime.go:655","msg":"Runtime event queue processor started","size":65536,"workers":8}
{"level":"info","ts":"2024-10-23T15:57:42.735Z","caller":"server/runtime_go.go:2794","msg":"Initialising Go runtime provider","path":"/nakama/data/modules"}
{"level":"error","ts":"2024-10-23T15:57:42.761Z","caller":"zarbe-runtime/main.go:52","msg":"Error creating official match: error creating match: not found","runtime":"go","source":"zarr.be/zarbe-runtime/main.go:52"}
{"level":"fatal","ts":"2024-10-23T15:57:42.761Z","caller":"server/runtime_go.go:2812","msg":"Error returned by InitModule function in Go module","name":"backend","error":"error creating match: not found"}

```

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [October 24, 2024, 10:30am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/17 "2024-10-24T10:30:32Z")

</div>

Hello @lucille, what version of Nakama are you observing this on? Have you tried upgrading to latest?

---

<div class="post-metadata">

**Author:** ![lucille](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lucille](https://forum.heroiclabs.com/u/lucille)\
**Post date:** [October 26, 2024, 9:41am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/18 "2024-10-26T09:41:24Z")

</div>

Hello @sesposito,

I’m currently using Nakama Docker `3.23.0`, and after upgrading to the latest version `3.24.2`, I’m still encountering the same issue. The server halts after reaching the line Initialising Go runtime provider and then exits unexpectedly.

Here are the relevant server logs:

```auto
+ /nakama/nakama migrate up --database.address root@cockroachdb:26257
{"level":"info","ts":"2024-10-23T16:06:29.228Z","caller":"server/db.go:140","msg":"Database information","version":"CockroachDB CCL v23.1.27 (x86_64-pc-linux-gnu, built 2024/10/02 05:11:25, go1.19.13)"}
{"level":"info","ts":"2024-10-23T16:06:29.229Z","caller":"migrate/migrate.go:109","msg":"Applying database migrations","limit":-1}
{"level":"info","ts":"2024-10-23T16:06:29.251Z","caller":"migrate/migrate.go:116","msg":"Successfully applied migration","count":0}
+ exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100
{"level":"warn","ts":"2024-10-23T16:06:29.302Z","caller":"server/config.go:323","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.username"}
{"level":"warn","ts":"2024-10-23T16:06:29.303Z","caller":"server/config.go:327","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.password"}
{"level":"warn","ts":"2024-10-23T16:06:29.303Z","caller":"server/config.go:331","msg":"WARNING: insecure default parameter value, change this for production!","param":"console.signing_key"}
{"level":"warn","ts":"2024-10-23T16:06:29.303Z","caller":"server/config.go:335","msg":"WARNING: insecure default parameter value, change this for production!","param":"socket.server_key"}
{"level":"warn","ts":"2024-10-23T16:06:29.303Z","caller":"server/config.go:339","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.encryption_key"}
{"level":"warn","ts":"2024-10-23T16:06:29.303Z","caller":"server/config.go:343","msg":"WARNING: insecure default parameter value, change this for production!","param":"session.refresh_encryption_key"}
{"level":"warn","ts":"2024-10-23T16:06:29.304Z","caller":"server/config.go:347","msg":"WARNING: insecure default parameter value, change this for production!","param":"runtime.http_key"}
{"level":"info","ts":"2024-10-23T16:06:29.304Z","caller":"main.go:136","msg":"Nakama starting"}
{"level":"info","ts":"2024-10-23T16:06:29.304Z","caller":"main.go:137","msg":"Node","name":"nakama1","version":"3.23.0+1811efb0","runtime":"go1.22.5","cpu":4,"proc":4}
{"level":"info","ts":"2024-10-23T16:06:29.304Z","caller":"main.go:138","msg":"Data directory","path":"/nakama/data"}
{"level":"info","ts":"2024-10-23T16:06:29.304Z","caller":"main.go:149","msg":"Database connections","dsns":["root@cockroachdb:26257"]}
{"level":"debug","ts":"2024-10-23T16:06:29.306Z","caller":"server/db.go:116","msg":"Complete database connection URL","raw_url":"postgres://root@cockroachdb:26257/nakama?sslmode=prefer"}
{"level":"info","ts":"2024-10-23T16:06:29.318Z","caller":"server/db.go:140","msg":"Database information","version":"CockroachDB CCL v23.1.27 (x86_64-pc-linux-gnu, built 2024/10/02 05:11:25, go1.19.13)"}
{"level":"info","ts":"2024-10-23T16:06:29.332Z","caller":"server/metrics.go:178","msg":"Starting Prometheus server for metrics requests","port":9100}
{"level":"info","ts":"2024-10-23T16:06:29.346Z","caller":"server/leaderboard_rank_cache.go:140","msg":"Initializing leaderboard rank cache"}
{"level":"info","ts":"2024-10-23T16:06:29.347Z","caller":"server/leaderboard_rank_cache.go:201","msg":"Leaderboard rank cache initialization completed successfully","cached":[],"skipped":[],"duration":"242.741µs"}
{"level":"info","ts":"2024-10-23T16:06:29.349Z","caller":"server/runtime.go:646","msg":"Initialising runtime","path":"/nakama/data/modules"}
{"level":"info","ts":"2024-10-23T16:06:29.350Z","caller":"server/runtime.go:653","msg":"Initialising runtime event queue processor"}
{"level":"info","ts":"2024-10-23T16:06:29.352Z","caller":"server/runtime.go:655","msg":"Runtime event queue processor started","size":65536,"workers":8}
{"level":"info","ts":"2024-10-23T16:06:29.352Z","caller":"server/runtime_go.go:2794","msg":"Initialising Go runtime provider","path":"/nakama/data/modules"}

```

Thank you!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [October 28, 2024, 11:51am UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/19 "2024-10-28T11:51:05Z")

</div>

@lucille are you using Docker?

Are you certain that your code changes are being loaded by the server correctly? I couldn’t reproduce this issue, and your latest logs show no error. The previous ones clearly state that there are no match handlers registered with name `default`. Where is the definition of `Match`?

---

<div class="post-metadata">

**Author:** ![lucille](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lucille](https://forum.heroiclabs.com/u/lucille)\
**Post date:** [October 28, 2024, 3:15pm UTC](https://forum.heroiclabs.com/t/static-default-matches/2418/20 "2024-10-28T15:15:00Z")

</div>

Yes, I’m using Docker.

Apologies for any confusion. In my original post, I shared a simplified version of my code, which overlooked an important detail regarding data types. The issue was indeed related to the typing in `MatchState`.

Here’s the structure I was using:

```go
type MatchState struct {
	Duration int64 `json:"duration"`
}

```

Initially, I attempted to pass parameters in this way:

```go
params := map[string]interface{}{
	"duration": 0,
}

```

However, this caused the server to halt and exit unexpectedly. It turns out that the type mismatch was the root of the issue. To resolve it, I specified the type explicitly:

```go
params := map[string]interface{}{
	"duration": int64(0),
}

```

Since there were no error messages or direct indicators, diagnosing the problem was challenging. Explicitly setting the type resolved the issue, and the server is now stable.

Regards.
