KcdMp.onMessage
Registers a function that receives what a client script or the game mode sent this frame with a message.
fn(data) is called with exactly the value that was sent - a client script’s SendWebMessage(frame, data) or the
mode’s SendPlayerWebMessage(pid, frame, data): a table arrives as an object or an array, a text as a text, and a page
never receives a message that only looks like the game’s own. Messages arrive in the order they were sent, and one
sent before the page called KcdMp.ready is kept and delivered when it does. Any number of functions may be
registered; each gets every message, and one that throws is logged and does not stop the others.
Syntax
Section titled “Syntax”KcdMp.onMessage(fn)| Parameter | Type | |
|---|---|---|
fn |
(data: unknown) => void |
called with each message |
Returns
Section titled “Returns”() => void - a function that takes the handler off again
Example
Section titled “Example”const off = KcdMp.onMessage((data) => { if (data && data.type === "notice") { showNotice(data.text); }});// later: off();See also
Section titled “See also”KcdMp.onServer · KcdMp.post · KcdMp.ready · the Messages and events group of the index
