Skip to content

Storage Server

The Storage Server block
Storage Server. Asset render of the block model, not an in-game screenshot.

The Storage Server is a shared notebook for a whole network. Every program on the network, on the computer and on devices, can store values under names and read them back later. Use it to collect logs from autonomous devices or to share settings between programs.

Storage Server

Shaped crafting table recipe. Progression: advanced automation. Ingredients: 4 × Iron Ingot, 2 × Chest, 2 × Comparator, 1 × Redstone. It appears in the recipe book once you pick up one of its ingredients.

Place it and link it to a Network Repeater. It needs no drive and runs no program.

Setting Meaning
Device programs: write / read Whether drive programs may change the data or only read it. Computer programs can always write.
View data Shows the stored keys.
Clear data Owner only: deletes everything stored.

nil, booleans, numbers, strings, lists, tuples and dictionaries, nested at most 16 levels, with no loops. Devices, class objects and enum constants cannot be stored. Every read gives a copy, so changing it does not change the stored value until you write it back.

The Storage Server cannot run a program, but drive programs on its network can use it through a device constant: const records = storageServers.named("records"), then records.append(...). They cannot clear() it.

storageServers.named(alias)

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

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

const records = storageServers.named("records")

storageServers.from(alias)

Resolve a storage server by name.

Parameters: alias: string. Gives: StorageServer, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: server.read. Cost: 16 operations.

server, err = storageServers.from("warehouse")

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

records.append(key, value)

Add a value to the end of the list under a key, creating the list when needed.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.append("visitors", name)

records.clear()

Remove everything stored on the server.

Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.clear()

records.delete(key)

Remove a key. Gives false when nothing was stored.

Parameters: key: string. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.delete("old")

records.has(key)

True when something is stored under a key.

Parameters: key: string. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

if server.has("diamonds") { print("stocked") }

records.keys()

List the stored keys, oldest first.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

names = server.keys()

records.read(key)

Read a copy of the value stored under a key. A missing key gives the error storage.missing.

Parameters: key: string. Gives: any value, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

count = server.read("diamonds")

records.usage()

Read used and capacity bytes and entries and maxEntries.

Gives: dict, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.read. Cost: 24 operations.

space = server.usage()

records.write(key, value)

Store a copy of a value under a key, replacing any old value.

Parameters: key: string, value: any value. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, storage.damaged, storage.full, storage.key, storage.missing, storage.type, storage.value. Capability: server.write. Cost: 24 operations.

server.write("diamonds", 64)
EventWhen it runs
connectedRuns when the device becomes reachable, for example after its area loads.
disconnectedRuns when the device stops being reachable: unloaded, unlinked or removed.
  • 256 KiB in up to 1,024 keys, each value at most 64 KiB.
  • Keys are 1 to 64 letters, digits or _ . : -.
  • A write that does not fit fails with storage.full and changes nothing.
  • Data is saved with the world, never per write. A crash loses changes since the last save.
const records = storageServers.named("records")
on startup {
records.append("boots", "started")
print(str(records.keys().length) + " keys stored")
}