Every device
What every block a computer drives has in common: an object of functions called with a dot, its type, several types on one block, errors when the block goes away.
A device is a block a computer drives: a Traffic Light, a chest, a Create machine, a monitor, a sensor of Create Aeronautics. peripheral.wrap and peripheral.find return an object for it: a table whose fields are the functions of that block, its methods. This page explains what all these objects have in common; the pages of each type (listed below) describe their methods.
local light = peripheral.wrap("left") -- the Traffic Light on the left face
light.set("green")
print(light.get()) -- green
print(light.type()) -- traffic_lightEvery computer drives devices, the Tube Computer included: against one of its six faces, or, from the Minicomputer on, anywhere on its Data Cable network. Names, searching and costs are explained in peripheral.
device.type() | The type of the device, the same name peripheral.type gives for the block. |
Calling methods
With a dot, not a colon. The methods of a device are plain functions stored in a table, not methods in the Lua sense: call them with a dot, light.set("green"). With a colon, Brass passes the object itself as the first argument, and the method receives a table where it expected text:
local light = peripheral.wrap("left")
light.set("red") -- right
light:set("red") -- wrong: bad argument #1 to 'set' (string expected, got table)An ordinary table. A device object can be stored in a variable or a table, passed to a function, and looked through with pairs. A short function lists the methods of any device, sorted:
local function methods(device)
local names = {}
for name, _ in pairs(device) do
table.insert(names, name)
end
table.sort(names)
return table.concat(names, " ")
end
for _, name in ipairs(peripheral.list()) do
print(name .. ": " .. methods(peripheral.wrap(name)))
endFor a Traffic Light, it prints get release set type. The built-in devices program goes further: it shows everything the computer can reach, with live readings.
An object only lives as long as the program: after a reboot, wrap the block again.
Types
Each device has a type, a short name in English that says what it can do. These are all the types, with the page of their methods:
| type | blocks | methods |
|---|---|---|
traffic_light | Traffic Light | Traffic Light |
inductive_loop | Inductive Loop Detector | Inductive Loop Detector |
monitor | CRT Monitor, LCD Monitor | Monitors |
wifi_router | Wi-Fi Router | Radio Modem and Wi-Fi Router |
radio_modem | Radio Modem | Radio Modem and Wi-Fi Router |
relay | Relay | Relay |
card_reader | Jacquard Card Reader | Jacquard Card Reader |
coil_winder | Coil Winder | Precision machines |
vacuum_chamber | Vacuum Chamber | Precision machines |
lithography_machine | Photolithography Machine | Precision machines |
ion_implanter | Ion Implanter | Precision machines |
pick_and_place | Pick-and-Place Machine | Precision machines |
crystal_puller | Crystal Puller | Precision machines |
redstone_link | Create's Redstone Link | Redstone Link |
creative_motor | Create's Creative Motor | Create machines |
speed_controller | Create's Rotation Speed Controller | Create machines |
speedometer | Create's Speedometer | Create machines |
stressometer | Create's Stressometer | Create machines |
sequenced_gearshift | Create's Sequenced Gearshift | Create machines |
sticker | Create's Sticker | Create machines |
display_link | Create's Display Link | Display Link and nixie tubes |
nixie_tube | Create's Nixie Tube | Display Link and nixie tubes |
station | Create's Train Station | Trains |
signal | Create's Train Signal | Trains |
track_observer | Create's Train Observer | Trains |
repackager | Create's Re-Packager | Create logistics |
packager | Create's Packager | Create logistics |
frogport | Create's Frogport | Create logistics |
postbox | Create's Postboxes | Create logistics |
redstone_requester | Create's Redstone Requester | Create logistics |
stock_ticker | Create's Stock Ticker | Create logistics |
table_cloth | Create's Table Cloths | Create logistics |
altitude_sensor | Altitude Sensor of Create Aeronautics | Create Aeronautics sensors |
gimbal_sensor | Gimbal Sensor of Create Aeronautics | Create Aeronautics sensors |
velocity_sensor | Velocity Sensor of Create Aeronautics | Create Aeronautics sensors |
optical_sensor | Optical Sensor of Create Aeronautics | Create Aeronautics sensors |
navigation_table | Navigation Table of Create Aeronautics | Create Aeronautics sensors |
swivel_bearing | Swivel Bearing of Create Aeronautics | Create Aeronautics sensors |
torsion_spring | Torsion Spring of Create Aeronautics | Create Aeronautics sensors |
directional_link | Directional Linked Receiver of Create Aeronautics | Create Aeronautics sensors |
modulating_link | Modulating Linked Receiver of Create Aeronautics | Create Aeronautics sensors |
docking_connector | Docking Connector of Create Aeronautics | Create Aeronautics sensors |
linked_typewriter | Linked Typewriter of Create Aeronautics | Create Aeronautics sensors |
name_plate | Nameplates of Create Aeronautics | Create Aeronautics sensors |
hot_air_burner | Hot Air Burner of Create Aeronautics | Hot Air Burner |
steam_vent | Steam Vent of Create Aeronautics | Hot Air Burner |
propeller_bearing | Propeller Bearing, Gyroscopic Propeller Bearing of Create Aeronautics | Propellers |
cannon_mount | Cannon Mount of Create Big Cannons | Cannon mounts |
fixed_cannon_mount | Fixed Cannon Mount of Create Big Cannons | Cannon mounts |
electric_motor | Electric Motor of Create Crafts & Additions | Create Crafts & Additions |
servo_motor | Servo Motor of Create Crafts & Additions | Create Crafts & Additions |
modular_accumulator | Accumulator of Create Crafts & Additions | Create Crafts & Additions |
portable_energy_interface | Portable Energy Interface of Create Crafts & Additions | Create Crafts & Additions |
redstone_relay | Redstone Relay of Create Crafts & Additions | Create Crafts & Additions |
digital_adapter | Digital Adapter of Create Crafts & Additions | Create Crafts & Additions |
electric_pump | Electric Pump of Create Crafts & Additions | Create Crafts & Additions |
liquid_blaze_burner | Blaze Burner with Straw of Create Crafts & Additions | Create Crafts & Additions |
kinetic_battery | Kinetic Battery of Create: Connected | Create: Connected blocks |
overstress_clutch | Overstress Clutch of Create: Connected | Create: Connected blocks |
centrifugal_clutch | Centrifugal Clutch of Create: Connected | Create: Connected blocks |
freewheel_clutch | Freewheel Clutch of Create: Connected | Create: Connected blocks |
sequenced_pulse_generator | Sequenced Pulse Generator of Create: Connected | Create: Connected blocks |
dashboard | Dashboard of Create: Connected | Create: Connected blocks |
linked_lever | Linked Lever of Create: Connected | Create: Connected blocks |
linked_button | Linked Buttons of Create: Connected | Create: Connected blocks |
linked_analog_lever | Linked Analog Lever of Create: Connected | Create: Connected blocks |
linked_throttle_lever | Linked Throttle Lever of Create: Connected (with Create Aeronautics) | Create: Connected blocks |
kinetic_bridge | Kinetic Bridge of Create: Connected | Create: Connected blocks |
sliding_breech | Sliding Breeches of Create Big Cannons | Cannon blocks |
screw_breech | Screw Breeches of Create Big Cannons | Cannon blocks |
cannon_loader | Cannon Loader of Create Big Cannons | Cannon blocks |
cannon_drill | Cannon Drill of Create Big Cannons | Cannon blocks |
cannon_cast | Cannon Cast of Create Big Cannons | Cannon blocks |
shell | the shells of Create Big Cannons (HE, shrapnel, AP...) | Cannon blocks |
big_cartridge | Big Cartridge of Create Big Cannons | Cannon blocks |
autocannon_ammo_container | Autocannon Ammo Container of Create Big Cannons | Cannon blocks |
blaze_enchanter | Blaze Enchanter of Create: Enchantment Industry | Enchantment Industry |
blaze_forger | Blaze Forger of Create: Enchantment Industry | Enchantment Industry |
printer | Printer of Create: Enchantment Industry | Enchantment Industry |
throttle_lever | Throttle Lever of Create Aeronautics | Create Aeronautics blocks |
laser_pointer | Laser Pointer of Create Aeronautics | Create Aeronautics blocks |
laser_sensor | Laser Sensor of Create Aeronautics | Create Aeronautics blocks |
redstone_accumulator | Redstone Accumulator of Create Aeronautics | Create Aeronautics blocks |
redstone_inductor | Redstone Inductor of Create Aeronautics | Create Aeronautics blocks |
physics_assembler | Physics Assembler of Create Aeronautics | Create Aeronautics blocks |
rope_winch | Rope Winch of Create Aeronautics | Create Aeronautics blocks |
spring | Springs of Create Aeronautics | Create Aeronautics blocks |
steering_wheel | Steering Wheel of Create Aeronautics | Create Aeronautics blocks |
analog_transmission | Analog Transmission of Create Aeronautics | Create Aeronautics blocks |
portable_engine | Portable Engines of Create Aeronautics | Create Aeronautics blocks |
andesite_propeller | Andesite Propeller of Create Aeronautics | Propellers |
wooden_propeller | Wooden Propeller of Create Aeronautics | Propellers |
smart_propeller | Smart Propeller of Create Aeronautics | Propellers |
mounted_potato_cannon | Mounted Potato Cannon of Create Aeronautics | Create Aeronautics blocks |
wheel_mount | Wheel Mount of Create Aeronautics (Offroad) | Create Aeronautics blocks |
borehead_bearing | Borehead Bearing of Create Aeronautics (Offroad) | Create Aeronautics blocks |
diesel_engine | Diesel Engine of Create: Diesel Generators | Diesel Generators |
modular_diesel_engine | Modular Diesel Engine of Create: Diesel Generators | Diesel Generators |
huge_diesel_engine | Huge Diesel Engine of Create: Diesel Generators | Diesel Generators |
burner | Burner of Create: Diesel Generators | Diesel Generators |
basin_lid | Basin Lid of Create: Diesel Generators | Diesel Generators |
bulk_fermenter | Bulk Fermenter of Create: Diesel Generators | Diesel Generators |
distillation_tank | Distillation Tank of Create: Diesel Generators | Diesel Generators |
pumpjack_hole | Pumpjack Hole of Create: Diesel Generators | Diesel Generators |
chemical_turret | Chemical Turret of Create: Diesel Generators | Diesel Generators |
motor | Basic, Advanced and Reinforced Motors of Create: New Age | Create: New Age |
motor_extension | Motor Extensions of Create: New Age | Create: New Age |
carbon_brushes | Carbon Brushes of Create: New Age | Create: New Age |
energiser | Energisers of Create: New Age | Create: New Age |
electrical_connector | Electrical Connector of Create: New Age | Create: New Age |
street_light | Street Light of Create: New Age | Create: New Age |
heater | Heater of Create: New Age | Create: New Age |
heat_pipe | Heat Pipe of Create: New Age | Create: New Age |
heat_pump | Heat Pump of Create: New Age | Create: New Age |
solar_heating_plate | Solar Heating Plates of Create: New Age | Create: New Age |
stirling_engine | Stirling Engine of Create: New Age | Create: New Age |
reactor_rod | Reactor Rod of Create: New Age | Create: New Age |
reactor_heat_vent | Reactor Heat Vent of Create: New Age | Create: New Age |
reactor_fuel_acceptor | Reactor Fuel Acceptor of Create: New Age | Create: New Age |
note_block | Minecraft's Note Block | Note Block |
kinetic | every Create block that turns: shafts, Millstone, Mechanical Press, Rotation Speed Controller... | Create kinetic blocks |
inventory | every block that holds items: chest, barrel, Item Vault, Depot, Basin... | Inventories |
tank | every block that holds fluids: Fluid Tank, Basin... | Tanks |
energy | every block that holds Forge Energy (FE): batteries, electric motors... | Energy blocks |
The types of a mod (Create Aeronautics, Create Big Cannons, Create Crafts & Additions...) only exist when that mod is installed.
One block, several types. A block can be several things at once. A Create Millstone turns and holds items: it is both kinetic and inventory. A Basin holds items and fluids: inventory and tank. Its object then has the methods of every type together, so one object does it all:
local millstone = peripheral.wrap("left")
print(millstone.speed() .. " RPM") -- a kinetic method
print(millstone.count() .. " items inside") -- an inventory methodIts type, though, is a single name: the first of its types, in the order of the table above (the types of one kind of block first, kinetic, inventory, tank and energy last). The Millstone is kinetic. To find a block by any of its types, use peripheral.list(type) or peripheral.find(type), which look at all of them: peripheral.find("inventory") finds the Millstone too.
device.type()
The type of the device, the same name peripheral.type gives for the block.
- string
- the type of the device: its first type
local device = peripheral.wrap("left")
if device and device.type() == "inventory" then
print(device.count() .. " items")
endIt is the type the block had when it was wrapped: the object keeps it, even if another block takes the place later.
A wrapped device always has a real type, since peripheral.wrap returns nil when there is nothing to talk to. Only peripheral.call("left", "type") on an empty face answers "none".
See also peripheral.type() peripheral.find()
When the block goes away
A device object does not hold the block itself: every method looks for the block again when it is called. So an object never goes stale. Break the chest on the left and put a new one there: the same object reads the new chest.
When the block is gone, or is no longer the right kind, the method stops the program with an error:
| message | when |
|---|---|
peripheral is not loaded | the block's chunk is not loaded (any type) |
traffic light removed | a Traffic Light is gone (set) |
monitor removed | a monitor is gone |
radio removed | a Radio Modem or Wi-Fi Router is gone |
redstone link not ready | a Redstone Link is gone, or not ready yet |
not a kinetic block anymore | a Create block that turned is gone |
not an inventory anymore | a block that held items is gone |
not a tank anymore | a block that held fluids is gone |
altitude sensor removed, hot air burner removed... | a block of Create Aeronautics is gone: its type, with spaces |
relay removed, station removed, display link removed... | any other block is gone: its name |
A few readings answer nil instead of failing: the get of a Traffic Light that is gone returns nil.
The methods of an object are chosen when it is wrapped. If a different kind of block takes the place (a barrel where the Traffic Light was), the old object keeps the methods of a Traffic Light, which now fail: wrap the block again.
To keep a program alive when a block may disappear, call the method through pcall, which returns a table instead of stopping the program:
local chest = peripheral.wrap("left")
while true do
local result = pcall(chest.count, "minecraft:coal")
if result.ok then
print("coal: " .. result.value)
else
print("the coal chest is missing!")
end
sleep(5)
endMore on catching errors: pcall and Errors and debugging.