Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --DIRECTIONS
- --Create file in main folder of computer named "mylog.log", this file hold variables though reboots.
- -- 0 down
- -- 1 up
- -- 2 north
- -- 3 south
- -- 4 west
- -- 5 east
- local w,h = term.getSize()
- drive=peripheral.wrap("top")
- local selection = 0
- local internalselection = 0
- local int range = 0
- local currentrange = 0
- local ypos = 1
- local counter = 1
- local direction
- --Some draw functions to get us started
- local function printCentered(str, ypos)
- term.setCursorPos(w/2 - #str/2, ypos)
- term.write(str)
- end
- local function printFarLeft(str, ypos)
- term.setCursorPos(1, ypos)
- term.write(str)
- end
- local function printLeft(str, ypos)
- term.setCursorPos(5, ypos)
- term.write(str)
- end
- local function printLeft2(str, ypos)
- term.setCursorPos(10, ypos)
- term.write(str)
- end
- local function printRight(str, ypos)
- term.setCursorPos(w - 15, ypos)
- term.write(str)
- end
- local function printRight2(str, ypos)
- term.setCursorPos(w - 25, ypos)
- term.write(str)
- end
- local function printFarRight(str, ypos)
- term.setCursorPos(w - #str, ypos)
- term.write(str)
- end
- function drawHeader()
- printCentered("Helm Control", 1)
- printCentered(string.rep("-", w+1), 2)
- -- Print Range
- printCentered("Range Left "..tostring(range),5)
- end
- function drawMainMenu()
- printLeft2("1. North", 7)
- printRight("5. Up", 7)
- printLeft2("2. South", 8)
- printRight("6. Down", 8)
- printLeft2("3. West", 9)
- printLeft2("4. East", 10)
- printRight("8. Quit", 10)
- printLeft2("Selection: ", 12)
- selection = tonumber(read())
- end
- function north()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("Forward", 7)
- printLeft("-------", 8)
- printLeft("1. Forward 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. Forward range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 2
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Forward Range", 7)
- printLeft("-------------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 2
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- end
- function south()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("Backward", 7)
- printLeft("--------", 8)
- printLeft("1. Backward 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. Backward range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 3
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Backward Range", 7)
- printLeft("-------------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 3
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- if internalselection==3 then
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- selection=0
- main()
- end
- end
- function west()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("West", 7)
- printLeft("----", 8)
- printLeft("1. West 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. West range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 4
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Down Range", 7)
- printLeft("----------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 4
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- if internalselection==3 then
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- selection=0
- main()
- end
- end
- function east()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("East", 7)
- printLeft("----", 8)
- printLeft("1. East 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. East range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 5
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Down Range", 7)
- printLeft("----------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 5
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- if internalselection==3 then
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- selection=0
- main()
- end
- end
- function up()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("Up", 7)
- printLeft("--", 8)
- printLeft("1. Up 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. Up range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 1
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Up Range", 7)
- printLeft("--------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 1
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- if internalselection==3 then
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- selection=0
- main()
- end
- end
- function down()
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- drawHeader()
- printLeft("Down", 7)
- printLeft("----", 8)
- printLeft("1. Down 1", 9)
- printRight("3. Main Menu", 9)
- printLeft("2. Down range", 10)
- printLeft("Selection: ", 12)
- internalselection = tonumber(read())
- if internalselection==1 then
- direction = 0
- --MOVE
- drive.move(direction,false,false)
- term.clear()
- term.setCursorPos(1,1)
- end
- if internalselection==2 then
- term.clear()
- term.setCursorPos(1,1)
- drawHeader()
- printLeft("Down Range", 7)
- printLeft("----------", 8)
- printLeft("How far: ", 9)
- currentrange = 0
- range = tonumber(read())
- direction = 0
- --Write memory file
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- --MOVE
- sleep(1)
- drive.move(direction,false,false)
- end
- if internalselection==3 then
- term.clear()
- term.setCursorPos(1,1)
- internalselection=0
- selection=0
- main()
- end
- end
- function main()
- --PROGRAM START
- term.clear()
- term.setCursorPos(1,1)
- myLog = fs.open("myLog.log", "r")
- if myLog then
- direction = tonumber(myLog.readLine())
- range = tonumber(myLog.readLine())
- end
- if (direction ~= "") and (range > 1) then
- range = range - 1
- startFile = fs.open("mylog.log", "w")
- startFile.writeLine(direction)
- startFile.writeLine(range)
- startFile.close()
- sleep(1)
- drive.move(direction,false,false)
- end
- while true do
- drawHeader()
- drawMainMenu()
- if selection==1 then
- north()
- end
- if selection==2 then
- south()
- end
- if selection==3 then
- west()
- end
- if selection==4 then
- east()
- end
- if selection==5 then
- up()
- end
- if selection==6 then
- down()
- end
- if selection==8 then
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment