Docs Quick code
Input
Keys, the mouse, gamepads, and the game's own controls (which players can change).
#The game's controls
Players can change which key does what (Options). Code that asks for a control by name keeps working whatever they chose — prefer these over fixed keys:
| Function | Gives |
|---|---|
action_down(action) |
true while that control is held. |
action_pressed(action) |
true once when it's pressed. |
Controls: "jump", "interact" (or "use"), "attack", "run", "forward", "back",
"left", "right", "inventory", "melee", "cast", "pause". Each also works on a gamepad.
#Keys and mouse buttons
| Function | Gives |
|---|---|
key_down(key) |
true while that key is held. |
key_pressed(key) |
true once when it goes down; false again until it's let go and pressed again. |
key_released(key) |
true once when it comes back up. |
Key names: letters and digits ("Q", "5"), "Space", "Shift", "Ctrl", "Alt", "Tab",
"Enter", "Up", "Down", "Left", "Right", "F1" …; mouse buttons: "Mouse Left",
"Mouse Right", "Mouse Middle", "Wheel Up", "Wheel Down", "Mouse 4", "Mouse 5".
while true do
if key_pressed("E") then
popup("Pressed E") -- once per press, however long it's held
end
wait(0)
end
"Pressed once" is kept per running code: two scripts watching the same key both see the press. To react to a key without a loop, use an Event node: Player presses a key / mouse button.
#The mouse
| Function | Gives |
|---|---|
mouse_x(), mouse_y() |
Where the mouse is on the screen, in pixels from the top left. |
mouse_tile() |
The tile under the mouse as a vector (x, level, z), or nil over the sky. |
-- Build where the player clicks.
while true do
if key_pressed("Mouse Right") then
local t = mouse_tile()
if t ~= nil then set_tile(t.x, t.y + 1, t.z, "Stone block") end
end
wait(0)
end
#Gamepads
| Function | Gives |
|---|---|
pad_down(button) / pad_pressed(button) |
A button held / pressed once: "A", "B", "X", "Y", "LB", "RB", "Start", "Back", "Up", "Down", "Left", "Right", "LS", "RS". |
pad_axis(stick) |
-1 … 1: "left_x", "left_y", "right_x", "right_y", "lt", "rt" (small wobbles read as 0). |