Skip to content

Control Panel

The Control Panel block
Control Panel. Asset render of the block model, not an in-game screenshot.

The Control Panel gives players four buttons. Each press runs your program’s handler, so a panel can switch an alarm on and off, open a gate or change a machine’s mode.

Control Panel

Shaped crafting table recipe. Progression: early automation. Ingredients: 4 × Any button, 3 × Iron Ingot, 1 × Redstone, 1 × Copper Ingot. It appears in the recipe book once you pick up one of its ingredients.

Place it where players can reach it; the buttons face you. Link it to a Network Repeater.

Right-click it with an empty hand. The owner and trusted players see the buttons and the settings:

  • press a button by selecting it;
  • choose Button 1 to 4, type a Label (1 to 24 characters) and select Save label;
  • switch restricted to public to let anyone press the buttons.

Visitors to a public panel only see the buttons. A press gives a click sound.

Yes: a panel with its own program handles device.buttonPressed and the other events. See the command panel tutorial.

controlPanels.named(alias)

Refer to a Control Panel by its name. Use it in a constant, then handle its events with on NAME.event(...).

Parameters: alias: string. Gives: ControlPanel. Cost: 4 operations.

const panel = controlPanels.named("panel")

controlPanels.from(alias)

Resolve a control panel by name.

Parameters: alias: string. Gives: ControlPanel, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: panel.control. Cost: 16 operations.

panel, err = controlPanels.from("gate_panel")

Properties: panel.connected, panel.id, panel.kind, panel.name. They are read-only.

panel.label(button)

Read one button's label. Use Button.ONE to Button.FOUR or 1 to 4.

Parameters: button: enum or number. Gives: string, or an error. Errors: argument.range, device.type, device.unavailable, device.unknown, host.denied. Capability: panel.control. Cost: 4 operations.

name = panel.label(Button.ONE)

panel.labels()

List the four button labels.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: panel.control. Cost: 4 operations.

names = panel.labels()

panel.setLabel(button, label)

Change a button's label: 1 to 24 characters.

Parameters: button: enum or number, label: string. Gives: bool, or an error. Errors: argument.range, device.type, device.unavailable, device.unknown, host.denied. Capability: panel.control. Cost: 16 operations.

panel.setLabel(Button.ONE, "Open Gate")
EventWhen it runs
buttonPressed(button)Runs when a player presses a button. button has id (Button.ONE to Button.FOUR), number, label and player.
buttonOne(player)Runs when button 1 is pressed. player is the name of who pressed it.
buttonTwo(player)Runs when button 2 is pressed.
buttonThree(player)Runs when button 3 is pressed.
buttonFour(player)Runs when button 4 is pressed.
connectedRuns when the device becomes reachable, for example after its area loads.
disconnectedRuns when the device stops being reachable: unloaded, unlinked or removed.
programStartedRuns when the device's own program starts.
programStoppedRuns when the device's own program stops.
programFailed(message)Runs when the device's own program stops on an error.

button in buttonPressed is {id, number, label, player}: id is Button.ONE to Button.FOUR, number is 1 to 4 and player is the presser’s name. The single-button events give the presser’s name.

const panel = controlPanels.named("panel")
on startup {
panel.setLabel(Button.ONE, "Lights on")
panel.setLabel(Button.TWO, "Lights off")
}
on panel.buttonPressed(button) {
print(button.player + " pressed " + button.label)
}