SendWebMessage
Sends a frame’s page a message - a table, a text, a number or a boolean.
The page’s KcdMp.onMessage handler receives exactly the value sent: a table arrives as an object or an array, a text
as a text. The message is written as JSON by JsonEncode, under its rules, and is at most 64 KB of it. A page that is
not ready yet is sent it when it is (up to 256 messages or 1 MB are kept per frame; past that the oldest are dropped);
messages arrive in the order they were sent. A table with a __kcdmp key at the top is refused: that key is how the game
itself talks to a page.
Returns true when the message was handed over, false and the reason when it could not be: "no web layer",
"no web interface", "no such frame", "no data" (the value is nil), "reserved key", "too big" or what
JsonEncode says about a value it cannot write.
Syntax
Section titled “Syntax”SendWebMessage(frame, data)| Parameter | Type | |
|---|---|---|
frame |
string | the frame’s name |
data |
table | string | number | boolean | the value the page receives |
Returns
Section titled “Returns”true, or false, reason - the reason as a person reads it
Example
Section titled “Example”-- the HUD page shows the player's speed, a few times a secondlocal since = 0function OnFrame(dt) since = since + dt if since >= 0.25 then since = 0 SendWebMessage("hud", { speed = 3.5 }) endendSee also
Section titled “See also”OnWebEvent · OnWebFrameReady · JsonEncode · the Web interface group of the index
