input#
Part of the scripting reference, written by the engine so it matches your frost. Start with your first game if you are new.
Use when binding keyboard, mouse, touch or gamepad controls, reading player actions or setting up multiplayer input.
| In a script | Does |
|---|---|
input.get("action", | A player's value for an action this step: an axis -1 to 1, a button 0 or 1. Players count from 0; left out, 0. The order before, input.get("action",, works for one more release with a warning (W0314) |
input.held("action", | Whether a player holds a button action (its value above one half); the player as for input.getInput.Get |
input.just_pressed("action",, input.just_released("action", | True only on the step a button action goes down (or up): held now and not the step before. Recorded input, so a replay agrees; player defaults to 0 |
input.capture(player, | Asks for a player's pointer to be captured (hidden and held, its motion read as MouseDeltaX/MouseDeltaY), or let go with false. The ask is world state, in the checksum; the device may refuse |
input.captured(player)Input.Captured(player) | Whether the device holds the pointer captured, as asked and granted: recorded input. A web page grants it at the next press on the canvas; Escape or a lost focus lets it go; a touch screen never grants it; network play reads false |
input.keys("action", | List of unique key/pad control names bound to the action for the last-used device; player defaults to 0. Before input, keyboard/pointer. Empty if unbound on that device; unknown actions are errors. Device changes are recorded and restored. Network play uses keyboard labels on all peers |
net.host()net.host(), net.join(address)net.join(address), net.cancel()net.cancel(), net.state()net.state(), net.player()net.player() | A menu's requests to play over a network, done after the step, and where it stands. Refused once the game plays with others. See [net] in frost reference project |
Input#
A script reads actions, never a device: input.get("move_x")Input.Get("move_x"). The project file says which keys drive which action ([input.keys]); a recording, a test or a protocol client drives the same actions, so the game cannot tell them from a hand.
The pointer (a mouse, or a finger on a touch screen) is actions too. Its buttons are keys, bound like any key, and a finger is "MouseLeft": fire = ["Space", "MouseLeft"]. Its place goes to the two actions the project names with pointer under [input], each -1 to 1 across the frame. In frame units, the units of an entity with Screen:
local x = (input.get("aim_x") + 1) / 2 * 320 -- the frame's width
local y = (input.get("aim_y") + 1) / 2 * 180 -- its heightOn a touch screen a game can follow two thumbs at once: each finger slot under [input] fingers is a part of the frame, and a finger that comes down in it drives that slot's three actions (its place and its press) until it lifts. They are read like any actions: input.get("move_x")Input.Get("move_x"), input.get("move")Input.Get("move").
The pointer's motion is four more axes, each by its name alone and with no end (an action bound to one is not held to -1 to 1): "MouseWheel" and "MouseWheelX" are the wheel's notches this step, away from the person and to the right (a line is a notch, a page 3, and a touchpad's or a browser's pixels a notch every 100); "MouseDeltaX" and "MouseDeltaY" are how far the pointer moved this step in the frame's pixels, right and up, also outside the frame. While the pointer is captured (input.captureInput.Capture) they are the mouse's own motion, so a drag never stops at the window's edge. A stick is a rate and the mouse a distance, so bind each to an action of its own (look_mouse = ["MouseDeltaX"], look_pad = ["PadRightX"]) and add them in the script, the pixels times a factor and the stick times degrees a second; bound to one action they are summed, not held to -1 to 1:
-- [input.keys] zoom = ["MouseWheel"] turn = ["MouseDeltaX"] hold = ["MouseRight"]
function step(dt)
input.capture(0, input.held("hold"))
if input.captured(0) then state.yaw = (state.yaw or 0) + input.get("turn") * 0.01 end
state.distance = math.clamp((state.distance or 8) - input.get("zoom"), 2, 30)
endA gamepad is bound in the same table: a button is a key, and a stick is an axis by its name alone, with a dead centre. The project file's [input.keys] lists every name:
[input.keys]
move_x = [{ negative = "A", positive = "D" }, "PadLeftX", { negative = "PadLeft", positive = "PadRight" }]
jump = ["Space", "PadA"]# Paths are relative to the folder the project file is in.
scene = "demo.toml" # required: the scene to load
space = "2d" # or "3d" for a 3D game (see 3D). Left out: "2d"
# Where the game is played: its defaults for what this file leaves out (anything written
# wins). "desktop" (left out): letterbox. "phone": fill, an icon made from the title at
# a phone export (W0463). "web": fill, and meant for a browser as with [web]. "handheld":
# fill, landscape. Every game gets touch controls made from its actions (see [input]);
# `frost check` says in one line what the profile gave.
profile = "phone"
scripts = ["demo.luau"] # Luau scripts, stepped in this order
# A saved test (a copy of a project file with its own recording) says which game it tests:
# `frost test --write` writes it. It plays nothing differently. Left out: the folder's game.toml.
# test_of = "game.toml"
# Optional: more scenes, which a script starts with scene.load("level2.toml"). `scene`
# itself can be loaded the same way, to start it again.
scenes = ["level2.toml"]
# What the game's saves are kept under on a player's machine: 1 to 64 of a to z, digits,
# `-`, `_` and `.`. Changing it orphans players' saves. Left out: an export warns
# and uses the folder's name.
id = "com.example.demo"
# A scene file may begin with `include = ["common.toml"]`: it starts with those
# scenes' entities (paths from this folder), then adds its own. A name written in
# both is an error (E0106), and an included scene includes nothing itself (E0426).# Optional: the actions that drive the game's menus and controls, each one of the
# `actions` under `[input]`, and each optional. `x` and `y` are axes that move the
# focus (and a slider), `accept` uses the node with the focus, `back` goes back out of
# a menu, and `press` is the pointer's button; the pointer's place is player 0's
# `[input] pointer`. The game may play with the same actions. `[ui.theme]` gives the colours (0xRRGGBB) a usable node takes: `normal`,
# `focus`, `pressed`, `off` and `locked`; one left out is not written. `start` names
# the node a menu opens on, if it is shown then; left out, the highest. Only a game with this table, or with a `Node` in a scene, has the
# interface's components. See Interface.
[ui]
# fit = 720 # Optional design height: screen-space drawing scales with the frame.
x = "move_x"
accept = "jump"
start = "play"# Optional: the picture. Left out: 960 by 540 and 0x15171c. A window may be any size: the
# frame keeps its shape, with the background beside it. A recording says the frame it was
# made in (`[input] frame`), so it comes to the same checksum anywhere.
[window]
# The frame in pixels, each side from 1 to 4096; one world unit is one pixel, the origin
# is the bottom-left corner, x grows to the right and y grows up.
size = [960, 540]
# The colour behind everything, as 0xRRGGBB.
background = 0x15171c
# How every picture is sampled when a sprite shows it at another size than its own:
# "nearest" keeps pixels sharp, for pixel art; "linear" blends them. Left out: "nearest".
filter = "nearest"
# How a phone holds the game: "landscape", "portrait" or "any" (whichever way it is
# turned); left out, landscape when the written frame is wider than tall.
orientation = "landscape"
# What the frame does on a screen of another shape: "letterbox" (the desktop profile's) keeps the
# frame's size and shape, with background bars beside it; "fill" takes the screen's shape
# (on a phone its safe part), keeping the height and growing the width, or keeping the
# width for a tall frame. `frame.size()` reports that frame; anchored UI follows its
# edges and cameras see more.
fit = "letterbox"
# Where the frame stands on a phone: "inside" (the desktop's) keeps it inside the safe
# area, clear of the notch, island and home bar, the background colour beside it; "under"
# (the phone profile's) makes it the whole screen: the world and screen things run under
# them, `frame.safe()` says how far in they reach (in the frame's units, input as the frame
# is: `[input] safe`; taken when the game starts, not again when the phone turns), and
# anchored UI keeps clear of them unless `Anchor.bleed`.
safe = "inside"# Optional: how the game is played over a network by rollback (`frost reference input`;
# the protocol's net.host, net.join and net.run). How many players it has is
# [input] players, 2 to 8 for a network. Left out: as written here.
[net]
delay = 2 # how many steps a player's input waits before its step, 0 to 8
window = 8 # how many steps may be played on predicted input and so played again, 1 to 16
sync_every = 30 # how many steps apart the peers compare the world's checksum, 1 to 600# Optional: the keys that drive the actions when the game runs in a window (`frost dev`,
# the player) or in a browser. A key is named by what a US keyboard prints on it:
# "A" to "Z", "0" to "9", "Space", "Enter", "Tab", "Escape", "Left", "Right", "Up",
# "Down", "PageUp", "PageDown", "Home", "End", "Insert", "Delete", "Backspace", "F1" to
# "F12", "ShiftLeft", "ShiftRight", "ControlLeft", "ControlRight", "AltLeft",
# "AltRight", "CapsLock", "BracketLeft", "BracketRight", "Semicolon", "Quote", "Comma",
# "Period", "Slash", "Backslash", "Minus", "Equal", "Backquote", "Numpad0" to "Numpad9",
# "NumpadAdd", "NumpadSubtract", "NumpadMultiply", "NumpadDivide", "NumpadDecimal",
# "NumpadEnter" (a key's place, whatever the layout prints on it, named as a browser's
# KeyboardEvent.code; F1 to F12 still do what the browser does, and a key the system or
# the browser keeps, as F5, Ctrl+W, Cmd+Q or Alt+F4, may never reach the game), and the
# pointer's buttons "MouseLeft", "MouseRight", "MouseMiddle" (a finger
# on a touch screen is "MouseLeft"). A gamepad is written the same way: its buttons
# are "PadA", "PadB", "PadX", "PadY" (A at the bottom), "PadL1", "PadR1", "PadL2",
# "PadR2", "PadSelect", "PadStart", "PadL3", "PadR3" (the sticks pressed), "PadUp",
# "PadDown", "PadLeft", "PadRight", and a stick is an axis by its name alone:
# "PadLeftX", "PadLeftY", "PadRightX", "PadRightY", with right and up as 1. The
# pointer's motion this step is "MouseWheel", "MouseWheelX" (notches) and "MouseDeltaX",
# "MouseDeltaY" (the frame's pixels), each an axis by its name alone, not held. A player's
# pad is the one with the player's number. A key name alone is a button for player 0: 1 while the key is down. A table
# is a button (`key`) or an axis (1 while `positive` is down, -1 while `negative`
# is), for `player` (left out: player 0). A list of them binds the action for several
# players on the one keyboard, or gives one player several keys for it: any of them
# presses a button, and an axis is the sum of its bindings, held to -1 to 1.
#
# An action bound to nothing here gets keys by its name: move_x/x/turn A,D, Left,Right,
# PadLeftX; move_y/y/walk S,W, Down,Up, PadLeftY; jump Space, PadA; fire/shoot/attack J,
# PadX; use/interact E, PadY; dash/run/sprint ShiftLeft, PadB; pause/menu Escape,
# PadStart; start Enter, PadStart; accept/confirm Enter, PadA; back/cancel Backspace, PadB.
#
# Optional, beside `actions`: the two actions that are told where the pointer is (the
# mouse, or a finger): pointer = { x = "aim_x", y = "aim_y" }, for `player` (left out:
# player 0). Each is an axis like any other: x is -1 at the frame's left edge and 1 at its right, y is -1 at the
# bottom and 1 at the top, and a pointer outside the frame is at the nearest edge. In
# frame units that is (x + 1) / 2 * width and (y + 1) / 2 * height.
#
# Touch controls with nothing written: made from the actions and their keys, the same
# every time. Axes (two keys, or a pad's stick) are a stick on the left (`_x` with `_y`,
# else one across with one up), a second stick on the right; a `pointer` with an action
# on "MouseLeft" an aim pad on the right; other buttons large ones on the right; pause
# (or menu) a small button in a top corner, placed clear of what the screen shows; [ui]
# accept and back the same, only while a menu's button shows; other menu actions (start,
# restart...) none. Drawn once a finger touches (from the start on a phone). A finger on
# one is not the pointer; one on a shown UI node is the pointer's. Move one with
# `[input.touch]`: `jump = "left"`, "right", "corner" or "none"; `tint = "#88c0d0"`
# colours them all. `frost check
# --explain-touch` prints them as `fingers`; `frost run --touch` draws them on shots.
#
# Optional: finger slots for a touch screen, up to 8 (in place of the made ones;
# `fingers = []` for none), each a `region` and three declared
# actions: fingers = [{ region = { x = -1, y = -1, w = 1, h = 2 }, x = "move_x",
# y = "move_y", press = "move" }] (that region is the left half), for `player` (left out:
# player 0). A region is in the units of the pointer's place: x, y its corner nearest -1,
# -1, then its width and height, the whole frame being 2 by 2; the frame is the game's own,
# as the pointer's is, and a finger over the bars beside it is at its nearest edge. A
# finger that comes down takes the first free slot, in the list's order, whose region holds
# its place (regions may overlap), and keeps it until it lifts, wherever it goes: the slot's
# `x` and `y` hold its place, -1 to 1 like the pointer's, and `press` is 1 while it is down.
# A finger in no free slot's region is no slot's. Slots are actions, so a recording, a test
# and a protocol client play them as they play keys. The first finger is still also the
# pointer with "MouseLeft": a menu under a slot's region sees both, so keep a game's buttons
# out of its slots' regions, or read one of the two.
# With `stick = 0.2` a slot's `x` and `y` are how far the thumb is from where it came
# down, over that fraction of the frame's height, kept within a unit circle; lifted, both
# are 0 (`press` may be left out). A slot with no `x` and `y` is a button: `press` alone.
# `shown = true` draws the slot: a disc with its `label` on it (left out: the name of its
# `press` action), or a stick's ring and the knob that follows the thumb, resting in the
# region's lower outer corner. A shown control is the size of a thumb, in points, inside
# the screen's safe area, translucent at rest and brighter while pressed, and never over
# a UI node that shows. It is part of the player's picture and of nothing else: no
# entity, not in the world, a checksum or a shot. `while_hidden = "panel"` draws a slot
# and gives it touches only while the node of that name is hidden, and `while_shown` only
# while it shows (a title's START, the stick of the play under it).
# `[input] controls = { color = 0xffffff, alpha = 0.35, size = 64 }` styles every slot:
# `size` is a button's width in points, and `alpha = 0` hides them all.
[input.keys]
jump = "Space"
move_x = [
{ negative = "A", positive = "D" },
{ player = 1, negative = "Left", positive = "Right" },
]
[input.touch]
jump = "left"Generated from Coldwave 0.0.1 r335, 2026-11-30 by the binary itself: do not edit by hand.