Advertisement
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 paintutensils
- 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
- --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
- --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(1)
- monitor.clear()
- 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
- 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
- local x,y = term.getSize()
- term.setTextScale(1)
- clear()
- local maxColumnLen = x/#decoded
- for i = 1, #decoded do
- local thisColumStarts = x / #decoded * (i-1) + 1
- term.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), 1 )
- term.write(decoded[i])
- end
- end
- 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])
- end
- end
- turtleDataFiles = fs.list("Turtles/")
- for n=1,#turtleDataFiles,1 do
- 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)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement