Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[In the Beginning:
- Perform first time Setup saving all Data needed inside the Data folder
- Get amount of files inside Turtles directory using fs.list()
- Next Step:
- Create Heading of Table
- Print out all current Data saved in Turtles Directory
- Draw lines using paintutils nope cause paintutils buggy as fuck
- wait for a rednet.receive then edit or create new File
- Repeat Next Step:
- ]]
- --VARIABLES
- local computerPeripherallsFile = "computerPeripheralls" --name of the File to save the Type of Computer
- local x,y = term.getSize() --Size of the screen
- local highlighted = 1
- local line
- local file
- local senderID, message, protocol
- --TABLES
- local computerPeripheralls = {} --Table to save the Data inside the computerPeripherallsFile
- local turtleDataFiles = {}
- local calculation = {}
- local decoded = {}
- --FUNCTION
- --TERM FUNCTIONS
- function resetScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- --MENU
- function writeChoices() --writes the choices down made for the menu
- for i=1,#choices do
- if i == highlighted then
- term.setCursorPos(((x/2)-(("<| "..choices[i].." |>"):len()/2)),i + 2)
- term.clearLine()
- term.write("<| "..choices[i].." |>")
- else
- term.setCursorPos(((x/2)-(choices[i]:len()/2)),i + 2)
- term.clearLine()
- term.write(choices[i])
- end
- end
- end
- function menuSelection() --waits for key input and changes the highlighted menuElemnt
- while true do
- writeChoices()
- local event, key = os.pullEvent( "key" )
- if key == keys.down then
- highlighted = highlighted + 1
- end
- if key == keys.up then
- highlighted = highlighted - 1
- end
- if key == keys.enter then
- chosenOne = choices[highlighted]
- break
- end
- if highlighted == 0 then
- highlighted = #choices
- end
- if highlighted == #choices + 1 then
- highlighted = 1
- end
- end
- end
- function Menu() --Creates a menu
- term.clear()
- term.setCursorPos(math.ceil((x/2)-(stringQuestionAsked:len()/2)),1)
- term.write(stringQuestionAsked)
- menuSelection()
- end
- --LOAD
- function load(fileName,arrayName) --Loading data that is inside File
- file = fs.open("Data/"..fileName,"r") -- Open a file for reading.
- line = file.readLine() -- This function reads the next line in the file, until the end.
- repeat -- Start a loop which will read lines into a table until no lines are left.
- table.insert(arrayName,line) -- Puts the value of the current line into the table we have.
- line = file.readLine() -- read the next line
- until line == nil -- readLine() returns nil when the end of the file is reached.
- file.close() -- Close up the file ready for use again.
- end
- function decode(text)
- local newString = {}
- for n=1,#text,1 do
- if string.sub(text,n,n) == "%" then
- table.insert(newString,n)
- end
- end
- for n=1,#newString,1 do
- if n-1 == 0 then
- table.insert(decoded,string.sub(text,1,newString[n]-1))
- else
- table.insert(decoded,string.sub(text,newString[n-1]+1,newString[n]-1))
- end
- end
- for n=1,#decoded,1 do
- print(decoded[n])
- end
- end
- --CREATE FILE
- function createFile(File) --Function that is used for the sole purpose of creating a file without editing it
- local file = fs.open("Data/"..File,"a")
- file.close()
- end
- --Big Table
- function bigTable(yCoordinate)
- computerPeripheralls = {}
- load(computerPeripherallsFile,computerPeripheralls)
- if computerPeripheralls[3] ~= 1 then
- local monitor = peripheral.wrap(computerPeripheralls[3])
- local x,y = monitor.getSize()
- monitor.setTextScale(0.85)
- local maxColumnLen = x/#decoded
- for i = 1, #decoded do
- local thisColumStarts = x / #decoded * (i-1) + 1
- monitor.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
- monitor.write(decoded[i])
- end
- else
- table.remove(decoded,5)
- table.remove(decoded,6)
- term.setTextScale(0.85)
- local x,y = term.getSize()
- clear()
- local maxColumnLen = x/#decoded
- for i = 1, #decoded do
- local thisColumStarts = x / #decoded * (i-1) + 1
- term.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
- term.write(decoded[i])
- end
- end
- decoded = {}
- end
- --CODE
- --FIRST TIME SETUP
- fs.makeDir("Data")
- fs.makeDir("Turtles")
- createFile(computerPeripherallsFile)
- computerPeripheralls = {}
- load(computerPeripherallsFile,computerPeripheralls)
- if computerPeripheralls[1] == nil then
- stringQuestionAsked = "This is a?"
- choices = {"Computer","Computer with Monitor","PocketComputer"}
- Menu()
- table.insert(computerPeripheralls,1,chosenOne)
- if computerPeripheralls[1] ~= "PocketComputer" then
- stringQuestionAsked = "Wireless Modem your Perspective?"
- choices = {"left","right","front","back","bottom","top"}
- Menu()
- table.insert(computerPeripheralls,2,chosenOne)
- if computerPeripheralls[1] == "Computer with Monitor" then
- stringQuestionAsked = "Where is the Monitor?"
- choices = {"left","right","front","back","bottom","top"}
- Menu()
- table.insert(computerPeripheralls,3,chosenOne)
- end
- end
- if computerPeripheralls[2] == nil then
- table.insert(computerPeripheralls,2,"1")
- table.insert(computerPeripheralls,3,"1")
- end
- if computerPeripheralls[3] == nil then
- table.insert(computerPeripheralls,3,"1")
- end
- local file = fs.open("Data/"..computerPeripherallsFile,"w")
- for i=1,#computerPeripheralls,1 do
- file.writeLine(computerPeripheralls[i])
- end
- file.close()
- end
- computerPeripheralls = {}
- load(computerPeripherallsFile,computerPeripheralls)
- if computerPeripheralls[1] ~= "PocketComputer" then
- rednet.open(computerPeripheralls[2])
- if computerPeripheralls[1] == "Computer with Monitor" then
- local monitor = peripheral.wrap(computerPeripheralls[3])
- monitor.clear()
- else
- clear()
- end
- else
- clear()
- end
- -- CODE
- while true do
- decoded = {"IDs","X","Z","Holes","Tracked Blocks"," "}
- bigTable(1)
- turtleDataFiles = fs.list("Turtles/")
- for n=1,#turtleDataFiles,1 do
- print(turtleDataFiles[n])
- file = fs.open("Turtles/"..turtleDataFiles[n],"r") -- Open a file for reading.
- line = file.readLine() -- This function reads the next line in the file, until the end.
- repeat -- Start a loop which will read lines into a table until no lines are left.
- table.insert(decoded,line) -- Puts the value of the current line into the table we have.
- line = file.readLine() -- read the next line
- until line == nil -- readLine() returns nil when the end of the file is reached.
- file.close() -- Close up the file ready for use again.
- bigTable(n+1)
- end
- print("wait")
- senderID, message, protocol = rednet.receive()
- decoded = {}
- decode(message)
- table.insert(decoded[1].." "..senderID)
- table.remove(decoded,2)
- local file = fs.open("Data/"..senderID,"w")
- for i=1,#decoded,1 do
- file.writeLine(decoded[i])
- end
- file.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment