Disk - iimurpyh/pilot-lua GitHub Wiki
A part used to store information for microcontrollers.
void Disk:ClearDisk()
void Disk:Write(string key, string value)
string Disk:Read(string key)
dictionary Disk:ReadEntireDisk()
Wipes the disk clean.
Writes
data
to the fieldkey
inside a disk.
Returns any data in the
key
field.
Returns all data as a dictionary.
Here are some code examples for disks.
local disk = GetPartFromPort(1, "Disk")
local keyb = GetPartFromPort(1, "Keyboard")
local thrusters = GetPartsFromPort(2, "Thruster")
local data = {
propulsion = disk:Read("Propulsion"); --> Let's say we're reading the saved propulsion for a spaceship that uses commands to change settings. We would want to initialise by reading the propulsion first.
} --> Always initialise by reading, I don't recommend spamming read calls, neither do I recommend spamming write calls.
--> We calibrate everything to the right settings.
for _, thruster in pairs(thrusters)do
thruster:Configure({ Propulsion = data.propulsion })
end
--> Mini command system, a player can change the propulsion simply by typing "setprop <propulsion>" on a keyboard.
--> Obviously, there are better ways to handle commands.
keyb:Connect("TextInputted", function(text)
local args = text:sub(1, #text-1):split(" ")
local cmd = args[1]
table.remove(args, 1)
if(cmd == "setprop")then
local newPropulsion = tonumber(args[1])
for _, thruster in pairs(thrusters)do
thruster:Configure({ Propulsion = newPropulsion })
end
disk:Write("Propulsion", newPropulsion)
end
end)