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
Section titled “device”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.
me, err = device.info()device.time()
Read world time where the device is: dayTime (0–23999, 0 is sunrise), day, gameTime, isDay, isNight.
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).
storage
Section titled “storage”The drive’s own storage. See storage for the full reference.
Other devices
Section titled “Other devices”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.
Custom events
Section titled “Custom events”events.emit, events.send and on events.custom(...) work as on a computer. See custom events.
Which devices can run programs
Section titled “Which devices can run programs”| Device | Program uses |
|---|---|
Entity Detector entity_detector | detector.read, devices.read, events.emit, server.read, server.write, storage.read, storage.write |
Weather Station weather_station | devices.read, events.emit, server.read, server.write, storage.read, storage.write, weather.read |
Redstone Controller redstone_controller | devices.read, events.emit, redstone.read, redstone.write, server.read, server.write, storage.read, storage.write |
Inventory Module inventory_module | devices.read, events.emit, inventory.read, inventory.transfer, server.read, server.write, storage.read, storage.write |
Environment Sensor environment_sensor | devices.read, environment.read, events.emit, server.read, server.write, storage.read, storage.write |
Display Module display | devices.read, display.read, display.write, events.emit, server.read, server.write, storage.read, storage.write |
Alarm Module alarm | alarm.write, devices.read, events.emit, server.read, server.write, storage.read, storage.write |
Access Controller access_controller | access.control, devices.read, events.emit, server.read, server.write, storage.read, storage.write |
Control Panel control_panel | devices.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.
Example
Section titled “Example”global last = ""
on device.weatherChanged(now, before) { entry = {weather: str(now), day: device.time().day} storage.append("weather", entry) last = str(now)}