Skip to main content

Disk

A programmable object capable of storing complex data. Be aware, while disks can store userdata & function values, it cannot save them. It is a craftable and spawnable non-flammable solid.

Here is a list of possible sizes that reach the maximum malleability (400) that have integer components: 1x1x400, 1x2x200, 1x4x100, 1x5x80, 1x8x50, 1x10x40, 1x16x25, 1x20x20, 2x2x100, 2x4x50, 2x5x40, 2x8x25, 2x10x20, 4x4x25, 4x5x20, 4x10x10, 5x5x16, 5x8x10

At its default size (0.5x4x4) it has a durability of 1, at its maximum size it has a durability of 4.

By default, its colour is #000000.

It requires 3 Copper, 10 Quartz, and 4 Silicon to be crafted.

Methods


Clear()

Clears all the contents of the disk.


Compress()


Decompress()


Read(key) → value

Reads the specified key from the disk and returns the value.

The key parameter can be anything.

The value return can be anything.


ReadAll() → content

Reads the entire content of the disk and outputs it as a dictionary.

The content return is the content of the disk as a dictionary. It is a dictionary with keys that are anys and values that are anys.


Write(key, value)

Write the specified key with the specified value to the disk.

The parameters for Write are as follows:

  • The key parameter is the key to write to the disk at. It can be anything.
  • The value parameter is the value to write to the disk. It can be anything.

WriteAll(content)

Replaces (to clarify, it does clear the original contents) the content of the disk with the specified dictionary.

Note that it will have bizzare behaviour when used with :ReadAll.

The content parameter is a dictionary with keys that are anys and values that are anys.

local repr = require("repr")

local disk = assert(GetPart("Disk"), "no disk connected")

local a = disk:ReadAll()
disk:Write("foo", "bar")

print(a.foo) -- bar

disk:WriteAll( { hello = "world", asd = "fgh" } )
local b = disk:ReadAll()

print(a.foo, b.foo) -- bar nil
print(a.hello, b.hello) -- world world

print(a == b) -- false
print(a == disk:ReadAll()) -- false
print(b == disk:ReadAll()) -- true

print(repr(a)) -- { asd = "fgh", foo = "bar", hello = "world" }
print(repr(b)) -- { asd = "fgh", hello = "world" }

ClearDisk()

warning

This method is deprecated. Superseded by Disk:Clear().

Clears the disk.


ReadEntireDisk() → content

warning

This method is deprecated. Superseded by Disk:ReadAll().

The content return is a dictionary with keys that are anys and values that are anys.

Events


Loop(tickInterval)

Fires when the object is updated by the game loop.

The tickInterval parameter is the inverse of the tick rate. For example, if the tick rate is 20, this will be 1 / 20 (or just 0.05). If the tick rate commands are accessible, running them will change this value. It is a number.