The controls a player holds
Unstable
load.input()
returns the
Input
of the server’s world: which of the game’s controls each player holds this
step. It is unstable: it needs the unstable feature (see
Stability).
Reading what a player holds
Section titled “Reading what a player holds”input.held(player) returns the game actions that player holds this step:
an InputMask, with contains(GameAction), iter() and the raw bits().
It reads the player’s own input in the server’s world, as their client last
sent it, so it reads a player without Enshwick the same way. It returns
None for an entity that is no player.
Input is Copy; get it during init and move it into ticks and handlers.
held runs on the server’s game thread between steps, such as in a tick.
Elsewhere it fails with a WorldError: WrongThread off the
game thread or inside a step, Missing before a world runs.
use std::time::Duration;
use enshwick::controls::GameAction;
fn init(load: &mut enshwick::Load<'_>) -> Result<(), enshwick::Off> { let input = load.input()?; let world = load.world()?; load.on_tick(Duration::from_secs(1), move |_| { for player in world.players() { if let Ok(Some(held)) = input.held(player.entity) && held.contains(GameAction::Block) { enshwick::info!("{} blocks", player.name); } } })?; Ok(())}enshwick.on_tick(1, function() for _, player in enshwick.world.players() do local held = enshwick.input.held(player.entity) if held ~= nil and table.find(held, "Block") then enshwick.log.info(`{player.name} blocks`) end endend)In Luau, held returns the list of the held actions’ game names, as a
control’s link names them, such as "ContextualAction_Tap".
Which bit is which
Section titled “Which bit is which”The game keeps the held controls as a 64-bit mask in each player’s
PlayerInput. The running build’s reflection names each bit, and the
loader maps each name to its GameAction. A bit the build does not name,
or that GameAction lacks, shows in bits() only.
What to trust
Section titled “What to trust”The held controls are what the player’s client sent, and a client can send any of them, as often as it likes. Read them for what the player could do with the keys anyway, such as a stance or a hint. Never let them decide rights, rewards or an admin step: those come from the server’s own state, or from a player action, which the server checks on every run.