Match Runtime Reference
This page lists all functions exposed in the match handler Dispatcher type.
Match runtime #
broadcast_message #
Send a message to one or more presences. This may be called at any point in the match loop to give match participants information about match state changes. May also be useful inside the match join callback to send initial state to the user on successful join. Note that when broadcasting to multiple presences, if any presence is invalid then the broadcast will not occur.
| Parameters |
|---|
| Name |
| --- |
| op_code |
| data |
| presences |
| sender |
| Returns |
|---|
| Name |
| --- |
| error |
<br> 1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br>10<br>11<br>12<br> |
lua<br>local nk = require("nakama")<br>function match_loop(context, dispatcher, tick, state, messages)<br> local opcode = 1234<br> local message = { ["hello"] = "world" }<br> local encoded = nk.json_encode(message)<br> local presences = nil -- send to all.<br> local sender = nil -- used if a message should come from a specific user.<br> dispatcher.broadcast_message(opcode, encoded, presences, sender)<br> return state<br>end<br> |
match_kick #
Removes participants from the match. Call at any point during the match loop to remove participants based on misbehavior or other game-specific rules.
| Parameters |
|---|
| Name |
| --- |
| presences |
| Returns |
|---|
| Name |
| --- |
| error |
<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br> |
lua<br>local nk = require("nakama")<br>function match_loop(context, dispatcher, tick, state, messages)<br> -- Assume we store presences in state<br> dispatcher.match_kick(state.presences)<br> return state<br>end<br> |
match_label_update #
Sets a new label for the match.
| Parameters |
|---|
| Name |
| --- |
| label |
| Returns |
|---|
| Name |
| --- |
| error |
<br>1<br>2<br>3<br>4<br>5<br>6<br> |
lua<br>local nk = require("nakama")<br>function match_loop(context, dispatcher, tick, state, messages)<br> dispatcher.match_label_update("updatedlabel")<br> return state<br>end<br> |