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 #da8541.
It requires 3 Copper
, 10 Quartz
, and 4 Silicon
to be crafted.
Methods
Clear()
Clears all the contents of the disk.
ClearDisk()
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 a dictionary with keys that are any
s and values that are any
s.
Write(key, value)
Write the specified key with the specified value to the disk.
The parameters for Write
are as follows:
- The key parameter can be anything.
- The value parameter 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 any
s and values that are any
s.
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" }
ReadEntireDisk() → content
This method is deprecated. Superseded by Disk:ReadAll()
.
The content return is a dictionary with keys that are any
s and values that are any
s.
Events
Loop(deltaTime)
Fires when the object is updated by the game loop.
The deltaTime parameter is the 'time' since the last tick, it does not represent the actual time since the last tick was occurred, rather just how often a game tick should be fired (it will always be precisely 1
). It is a number
.