Command
The two commands a player sends: moveY nudges your
paddle, and ready toggles your ready flag between matches. Each command is a folder with
its parameter schema, its writes manifest, and the server handler that applies it.
<gamehoster-config-contentRoot>/
game.gamehoster.org/
gamehoster-games/
pong/
gamehoster-commands/
moveY/
gamehoster-command.json
gamehoster-command-schema.json
gamehoster-command-handler.js
ready/
gamehoster-command.json
gamehoster-command-schema.json
gamehoster-command-handler.js
Contents
One folder per command; each holds a parameter schema, a writes manifest and a handler.
| Name | Type | Description |
|---|---|---|
moveY/ | directory | Nudge the paddle; writes player.y. |
ready/ | directory | Toggle the ready flag; writes player.ready. |
moveY/
Nudges the sending player's paddle. Its one param, axis, is a signed amount the renderer
keeps between -1 and 1, which the handler scales by paddleSpeed on the server. It writes
player.y, a public field, so the new paddle
position streams to both players.
gamehoster-command.json
{
"writes": ["player.y"]
}
gamehoster-command-schema.json
[
{
"gamehoster-command-schema-name": "axis",
"gamehoster-command-schema-type": "number"
}
]
gamehoster-command-handler.js
// Move the sending player's paddle by their axis input, on the authoritative server. `y` is
// public, so the new paddle position streams to both players. Ignored outside the playing phase.
const here = Gamehoster.Context.instanceId
if (Gamehoster.Instance.State.Get(here, "phase") !== "playing") return
const me = Gamehoster.Context.playerId
const speed = Gamehoster.Instance.State.Get(here, "paddleSpeed")
const half = Gamehoster.Instance.State.Get(here, "paddleH") / 2
const court = Gamehoster.Instance.State.Get(here, "courtH")
const y = Gamehoster.Player.State.Get(me, "y") + Gamehoster.Command.Get("axis") * speed
Gamehoster.Player.State.Set(me, "y", Math.max(half, Math.min(court - half, y)))
ready/
Flips the sending player's ready flag while the match is waiting or over,
which is how a game gets started or replayed once both players are ready. It takes no params. It writes
player.ready, a public field, and is ignored
during play.
gamehoster-command.json
{
"writes": ["player.ready"]
}
gamehoster-command-schema.json
[]
gamehoster-command-handler.js
// Toggle the sending player's ready flag while gathering or on the results
// screen. `ready` is a public field, so this handler runs on the authoritative
// server. Ignored during play.
const here = Gamehoster.Context.instanceId
const phase = Gamehoster.Instance.State.Get(here, "phase")
if (phase !== "waiting" && phase !== "over") return
const me = Gamehoster.Context.playerId
Gamehoster.Player.State.Set(me, "ready", !Gamehoster.Player.State.Get(me, "ready"))