Skip to content

KcdMp.call

Calls an action of the game’s interface component this frame draws.

A frame that draws one of the game’s components in place of the standard drawing - the chat, for one - can call the component’s actions ("chat.send"): what the component does through the game itself. The actions of each component are part of its contract (KcdMp.onComponent lists the chat’s and the scoreboard’s), and an action is available to that frame alone, while it draws the component. An action that needs the player’s own input (buying, answering a dialogue) is refused unless a real key or click reached the frame in the last second.

Any other action name - and any name from a frame that draws no component - rejects with "unknown action"; wrong data rejects with what is wrong with it, a chat.send while the chat’s box is closed with "the chat box is not open", and more than four lines a second with "too many lines".

await KcdMp.call(action, data?)
Parameter Type
action string the action’s name, as its component’s contract gives it
data unknown the action’s arguments, any JSON value (optional)

Promise<unknown> - the action’s answer, read from JSON

try {
await KcdMp.call("chat.send", { text: "Good day!" });
} catch (e) {
KcdMp.log.warn("chat.send: " + e.message);
}

KcdMp.contract · KcdMp.env.component · the Messages and events group of the index