Skip to content

Device programs

A program on a data drive runs on its device. Instead of finding devices by name, it uses device for its own hardware and storage for the drive’s data.

device.<method>(…) calls one of the device’s own hardware methods, such as device.activate() on an Alarm Module or device.read() on a Weather Station. Two more functions work on every programmable device:

device.info()

Describe this device and its drive: id, name, kind, drive, driveLabel.

Gives: dict, or an error. Capability: devices.read. Cost: 8 operations.

me, err = device.info()

device.time()

Read world time where the device is: dayTime (0–23999, 0 is sunrise), day, gameTime, isDay, isNight.

Gives: dict, or an error. Errors: device.unavailable. Capability: devices.read. Cost: 8 operations.

now, err = device.time()

On a Weather Station, device.time() is the station’s own time method, which also includes fixedTime.

Events of the device itself are on device.<event>, such as on device.entityEnter(entity).

The drive’s own storage. See storage for the full reference.

A drive program may declare device constants such as const gate = detectors.named("gate") and handle their events, for devices on the same network connected to it through loaded devices. It cannot call their methods, with one exception: a Storage Server constant offers its storage methods (except clear), unless its owner made it read-only for device programs.

It cannot use devices.list(), from(...) factories, drives.from(...) or the older port functions.

events.emit, events.send and on events.custom(...) work as on a computer. See custom events.

DeviceProgram uses
Entity Detector entity_detectordetector.read, devices.read, events.emit, server.read, server.write, storage.read, storage.write
Weather Station weather_stationdevices.read, events.emit, server.read, server.write, storage.read, storage.write, weather.read
Redstone Controller redstone_controllerdevices.read, events.emit, redstone.read, redstone.write, server.read, server.write, storage.read, storage.write
Inventory Module inventory_moduledevices.read, events.emit, inventory.read, inventory.transfer, server.read, server.write, storage.read, storage.write
Environment Sensor environment_sensordevices.read, environment.read, events.emit, server.read, server.write, storage.read, storage.write
Display Module displaydevices.read, display.read, display.write, events.emit, server.read, server.write, storage.read, storage.write
Alarm Module alarmalarm.write, devices.read, events.emit, server.read, server.write, storage.read, storage.write
Access Controller access_controlleraccess.control, devices.read, events.emit, server.read, server.write, storage.read, storage.write
Control Panel control_paneldevices.read, events.emit, panel.control, server.read, server.write, storage.read, storage.write

The second column lists the capabilities a program on that device holds.

global last = ""
on device.weatherChanged(now, before) {
entry = {weather: str(now), day: device.time().day}
storage.append("weather", entry)
last = str(now)
}