Skip to content

KcdMp.mock.reply

Sets what KcdMp.post answers for a name.

In mock mode KcdMp.post(name, data) calls fn(data) and resolves to what it returns (or to what a returned promise resolves to), where in the game a client script’s OnWebEvent would answer. A name without a reply answers { ok: true, mock: true }.

KcdMp.mock.reply(name, fn)
Parameter Type
name string the call’s name
fn (data: unknown) => unknown answers the call

nothing

KcdMp.mock.reply("buy", (data) => ({ ok: data.item === "bread" }));
const reply = await KcdMp.post("buy", { item: "bread" }); // { ok: true }

KcdMp.post · KcdMp.mock.emit · the Mock mode group of the index