SendPlayerWebMessage
Sends one page a message - a table, a text, a number or a boolean.
The page’s KcdMp.onMessage handler receives exactly the value that was sent: a table arrives as an object or an
array, a text as a text. Messages and events reach a page in the order they were sent; one for a page that is not ready
yet is kept for it (up to 256 messages or 1 MB per frame - past that the oldest are dropped) and handed over once
OnPlayerWebReady has run. A hidden frame receives its messages as well. Use SendClientEvent for what should
reach every page that listens for a name rather than one frame.
data is written as JSON by JsonEncode, under the same rules. A message is at most 60000 bytes of JSON. The
answer is true when it was handed to the player’s game; false and the reason otherwise: "no such player",
"no web interface", "the player has no web layer", "no such frame", "no data" (the value is nil),
"too big", "reserved key" (a table with a __kcdmp key at the top: that key is how the game itself talks to a page)
or what JsonEncode says about a value it cannot write.
Syntax
Section titled “Syntax”SendPlayerWebMessage(pid, frame, data)| Parameter | Type | |
|---|---|---|
pid |
number | the player |
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 ("too big", "no such frame" …)
Example
Section titled “Example”-- the arena's scoreboard page gets the standings every time they changefunction pushStandings(pid) local rows = {} for _, id in ipairs(GetPlayers()) do rows[#rows + 1] = { name = GetPlayerName(id), kills = kills[id] or 0 } end local ok, why = SendPlayerWebMessage(pid, "scoreboard", { rows = rows }) if not ok then Log("standings: " .. why) endendSee also
Section titled “See also”SendClientEvent · JsonEncode · OnPlayerWebReady · ShowPlayerWebFrame · the Web interface group of the index
