Disk - iimurpyh/pilot-lua GitHub Wiki

A part used to store information for microcontrollers.

Table of contents

Methods


void Disk:ClearDisk()

Wipes the disk clean.


void Disk:Write(string key, string data)

Writes data to the field key inside a disk.


string Disk:Read(string key)

Returns any data in the key field.


dictionary Disk:ReadEntireDisk()

Returns all data as a dictionary.


Code examples

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)
⚠️ **GitHub.com Fallback** ⚠️