Documentation

Game logic

v3 · Preview

Framework v3 is an opt-in preview available to everyone. New games use the stable framework by default.

Apply an action

apply_action

Applies one move. Before the call, the platform has checked that the game offered this action to this seat and that a command's value fits its input. So the game logic handles only moves it offered.

  • Return Ok(()) after the change.
  • Return Err(reason) to refuse a move by a rule the offer could not express, such as a city name another seat already took. reason is a message from the game's catalogs, Err(msg!("refusal.city-taken", city = name)), which the player sees in their language. Every change of the call is undone. Prefer narrowing the offers to refusing.
  • A reason is a message like a label (Offers): no {player}, and one that names a seat that is not seated panics.
  • A panic is a bug. It fails the move and is reported as a match error.

Read a command's value with action.text() or action.integer(). Match a command by name:

match action {
    Action::Command { name, .. } if name == "pass" => {
        table.log(msg!("log.passes"));
    }
    Action::PieceClick { space_id, index } => {
        table.move_piece(space_id, *index, "discard");
    }
    _ => {}
}

Need a hand with this?

Join our Discord