JavaScript SDK — Room Actions

Room Actions — mp.actions

send
await mp.actions.send(playerToken, actionType, requestData, { target?, targetIds? })

Issues a request/response action. target: 'all' | 'host' | 'others' | 'specific' (+targetIds for specific).

poll
await mp.actions.poll(playerToken)

Polls actions addressed to the player — clients answer via complete().

pending
await mp.actions.pending(playerToken)

Lists the player's own unanswered actions.

complete
await mp.actions.complete(playerToken, actionId, status, responseData?)

Answers an action — status marks it accepted/declined/completed with optional response payload.

Request/response actions

Actions are the room's request/response primitive — trades, votes, dialogs, ability prompts. Send issues a typed action at a target set: everyone, the host, everyone-but-you, or an explicit list of player ids. Each action carries a request payload and waits for an answer rather than firing and forgetting.

Recipients poll for actions addressed to them and answer with complete — a status marking it accepted, declined or completed, plus an optional response payload. Pending lists the sender's own still-unanswered actions, so a reconnecting client can rebuild its outstanding-request view.

  • The action type string is game-defined — version it like a protocol field as your game evolves.
  • Actions persist until answered: poll after rejoining so missed requests still get a response.
  • Need fire-and-forget state instead? Use room updates for durable state and realtime for ephemeral events.
  • Every call returns a Promise — await inside async functions. In browsers requests run over fetch with CORS; on Node.js 22.12+ the identical API uses the built-in fetch.