UNOBTANIUM

SmartProgrammer

Apr 26th, 2013
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.16 KB | None | 0 0
  1. version = "Smart Programmer 0.2.1"
  2. running = true
  3. w,h = term.getSize()
  4. select = 1
  5. a, b, c, d, e, f, z = 6,7,8,9,10,11,h-2
  6. newroute ,route = {}, {}
  7. listOfRoutes = {}
  8. runningRoute = ""
  9. currentPoint= 0
  10. currentStepPoint = 1
  11.  
  12.  
  13. --PRINT
  14.  
  15. function printCentered(str, ypos)
  16.  term.setCursorPos(w/2 - #str/2, ypos)
  17.  term.write(str)
  18. end
  19.  
  20. function drawCopyright()
  21.  local str = "by UNOBTANIUM"
  22.  term.setCursorPos(w-#str, h)
  23.  term.write(str)
  24. end
  25.  
  26. function drawHeader(title, line)
  27.  printCentered(title, line)
  28.  printCentered(string.rep("-", w), line+1)
  29. end
  30.  
  31. function clearScreen()
  32.  term.clear()
  33.  term.setCursorPos(1,1)
  34.  term.clear()
  35. end
  36.  
  37. --SAVE & LOAD & DELETE
  38.  
  39. function saveListOfRoutes()
  40.  local file = fs.open("listOfRoutes", "w")
  41.  for i=1, countArray(listOfRoutes) do
  42.   file.writeLine(listOfRoutes[i])
  43.  end
  44.  file.close()
  45. end
  46.  
  47. function loadListOfRoutes()
  48.  if fs.exists("listOfRoutes") then
  49.   local file = fs.open("listOfRoutes", "r")
  50.   local line = file.readLine()
  51.   local j = 1
  52.   while line do
  53.    listOfRoutes[j] = line
  54.    j = j + 1
  55.    line = file.readLine()
  56.   end
  57.   file.close()
  58.  end
  59. end
  60.  
  61. function saveSavepoint(input1, input2)
  62.  local file = fs.open("Savepoint", "w")
  63.  file.writeLine(tonumber(input1))
  64.  file.writeLine(runningRoute)
  65.  file.writeLine(tonumber(input2))
  66.  file.close()
  67. end
  68.  
  69. function loadSavepoint()
  70.  local file = fs.open("Savepoint", "r")
  71.  currentPoint = tonumber(file.readLine())
  72.  runningRoute = file.readLine()
  73.  currentStepPoint = tonumber(file.readLine())
  74.  file.close()
  75. end
  76.  
  77.  
  78. function saveRoute(name)
  79.  local file = fs.open(name, "w")
  80.  for i=1, countArray(route) do
  81.   file.writeLine(route[i])
  82.  end
  83.  file.close()
  84.  local routeAllreadyExists = false
  85.  if countArray(listOfRoutes) > 0 then
  86.   for i=1, countArray(listOfRoutes) do
  87.    if listOfRoutes[i] == name then
  88.     routeAllreadyExists = true
  89.    end
  90.   end
  91.  end
  92.  if not routeAllreadyExists then
  93.   table.insert(listOfRoutes, 1, name)
  94.  end
  95.  saveListOfRoutes()
  96. end
  97.  
  98. function resetRoute()
  99.  for i=1, countArray(route) do
  100.   route[i] = nil
  101.  end
  102. end
  103.  
  104. function loadRoute(name)
  105.  local file = fs.open(tostring(name), "r")
  106.  resetRoute()
  107.  local line = file.readLine()
  108.  local j = 1
  109.  while line do
  110.   route[j] = line
  111.   j = j + 1
  112.   line = file.readLine()
  113.  end
  114.  file.close()
  115. end
  116.  
  117. function deleteRoute(name)
  118.  if countArray(listOfRoutes) > 0 then
  119.   for i=1, countArray(listOfRoutes) do
  120.    if listOfRoutes[i] == name then
  121.     table.remove(listOfRoutes ,i)
  122.    end
  123.   end
  124.   saveListOfRoutes()
  125.  end
  126. end
  127.  
  128. -- MENUS
  129.  
  130. function drawMenuMain()
  131.  drawHeader(version, 1)
  132.  drawCopyright()
  133.  
  134.  if select == 1 then
  135.   printCentered("> Start <", a)
  136.  else
  137.   printCentered("Start", a)
  138.  end
  139.  if select == 2 then
  140.   printCentered("> New <", b)
  141.  else
  142.   printCentered("New", b)
  143.  end
  144.  if select == 3 then
  145.   printCentered("> Delete <", c)
  146.  else
  147.   printCentered("Delete", c)
  148.  end
  149.  if select == 4 then
  150.   printCentered("> Quit <", z-2)
  151.  else
  152.   printCentered("Quit", z-2)
  153.  end
  154. end
  155.  
  156.  
  157. -- MENUSTATE
  158.  
  159. local menustate = "main"
  160.  
  161. local mopt = {
  162.  ["main"] = {
  163.   options = {"start", "new", "delete", "quit"},
  164.   draw = drawMenuMain
  165.  }
  166. }
  167.  
  168. function runMenu()
  169.  while running do
  170.   clearScreen()
  171.   mopt[menustate].draw()
  172.  
  173.   local id, key = os.pullEvent("key")
  174.   if key == 200 or key == 17 then
  175.    select = select-1
  176.   end
  177.   if key == 208 or key == 31 then
  178.    select = select+1
  179.   end
  180.   if key == 14 or key == 30 then
  181.    if not menustate == "quit" then
  182.     select = #mopt[menustate].options
  183.     menustate = mopt[menustate].options[select]
  184.     select = 1
  185.    else
  186.     clearScreen()
  187.     running = false
  188.     break
  189.    end
  190.   end
  191.   if select == 0 then
  192.    select = #mopt[menustate].options
  193.   end
  194.   if select > #mopt[menustate].options then
  195.    select = 1
  196.   end
  197.   clearScreen()
  198.   if key == 28 or key == 32 then
  199.    if mopt[menustate].options[select] == "quit" then
  200.     running = false
  201.    elseif mopt[menustate].options[select] == "start" then
  202.     startRoute()
  203.    elseif mopt[menustate].options[select] == "new" then
  204.     createNewRoute()
  205.    elseif mopt[menustate].options[select] == "delete" then
  206.     selectRoute()
  207.     if runningRoute == "" then else
  208.      deleteRoute(runningRoute)
  209.     end
  210.    elseif true then
  211.     menustate = mopt[menustate].options[select]
  212.     select = 1
  213.    end
  214.   end
  215.  end
  216. end
  217.  
  218.  
  219.  
  220. -- IMPORTANT FUNCTIONS
  221.  
  222. function countArray(array)
  223.  local actions = 0
  224.  for k,v in pairs(array) do
  225.   actions = actions + 1
  226.  end
  227.  return actions
  228. end
  229.  
  230. local function transfer(i)
  231.  if i == 2 then
  232.   return "1"
  233.  elseif i == 3 then
  234.   return "2"
  235.  elseif i == 4 then
  236.   return "3"
  237.  elseif i == 5 then
  238.   return "4"
  239.  elseif i == 6 then
  240.   return "5"
  241.  elseif i == 7 then
  242.   return "6"
  243.  elseif i == 17 then
  244.   return "w"
  245.  elseif i == 30 then
  246.   return "a"
  247.  elseif i == 31 then
  248.   return "s"
  249.  elseif i == 32 then
  250.   return "d"
  251.  elseif i == 57 then
  252.   return "spacebar"
  253.  elseif i == 42 then
  254.   return "shift"
  255.  elseif i == 19 then
  256.   return "refuel"
  257.  elseif i == 16 then
  258.   return "suck"
  259.  elseif i == 18 then
  260.   return "drop"
  261.  elseif i == 21 then
  262.   return "attack"
  263.  elseif i == 45 then
  264.   return "redstone"
  265.  elseif i == 29 then
  266.   return "strg"
  267.  elseif i == 46 then
  268.   return "select"
  269.  elseif i == 28 then
  270.   return "enter"
  271.  else
  272.   return ""
  273.  end
  274. end
  275.  
  276. function savePos(a, b, c)
  277.  if b < c then
  278.   saveSavepoint(a,b+1)
  279.  else
  280.   saveSavepoint(a+2,1)
  281.  end
  282. end
  283.  
  284. function makeAction(j ,action, amount)
  285.  j = tonumber(j)
  286.  amount = tonumber(amount)
  287.  
  288.  if action == "w" then
  289.   for i=currentStepPoint,amount do
  290.    savePos(j,i,amount)
  291.    while not turtle.forward() do
  292.     saveSavepoint(j,i)
  293.     while turtle.detect() do
  294.      sleep(1)
  295.     end
  296.     savePos(j,i,amount)
  297.    end
  298.   end
  299.  elseif action == "s" then
  300.   for i=currentStepPoint, amount do
  301.    savePos(j,i,amount)
  302.    while not turtle.back() do
  303.     saveSavepoint(j,i)
  304.     sleep(1)
  305.    end
  306.    savePos(j,i,amount)
  307.   end
  308.  
  309.  elseif action == "spacebar" then
  310.   for i=currentStepPoint, amount do
  311.    savePos(j,i,amount)
  312.    while not turtle.up() do
  313.     saveSavepoint(j,i)
  314.     while turtle.detectUp() do
  315.      sleep(1)
  316.     end
  317.     savePos(j,i,amount)
  318.    end
  319.   end
  320.  elseif action == "shift" then
  321.   for i=currentStepPoint, amount do
  322.    savePos(j,i,amount)
  323.    while not turtle.down() do
  324.     saveSavepoint(j,i)
  325.     while turtle.detectDown() do
  326.      sleep(1)
  327.     end
  328.     savePos(j,i,amount)
  329.    end
  330.   end
  331.  elseif action == "a" then
  332.   saveSavepoint(j+2,1)
  333.   turtle.turnLeft()
  334.  elseif action == "d" then
  335.   saveSavepoint(j+2,1)
  336.   turtle.turnRight()
  337.  elseif action == "attack" then
  338.   saveSavepoint(j+2,1)
  339.   turtle.attack()
  340.  elseif action == "suckUp" then
  341.   saveSavepoint(j+2,1)
  342.   turtle.suckUp()
  343.  elseif action == "suckDown" then
  344.   saveSavepoint(j+2,1)
  345.   turtle.suckDown()
  346.  elseif action == "suckFront" then
  347.   saveSavepoint(j+2,1)
  348.   turtle.suck()
  349.  elseif action == "dropUp" then
  350.   saveSavepoint(j+2,1)
  351.   turtle.dropUp(amount)
  352.  elseif action == "dropDown" then
  353.   saveSavepoint(j+2,1)
  354.   turtle.dropDown(amount)
  355.  elseif action == "dropFront" then
  356.   saveSavepoint(j+2,1)
  357.   turtle.drop(amount)
  358.  elseif action == "select" then
  359.   saveSavepoint(j+2,1)
  360.   turtle.select(amount)
  361.  elseif action == "rw" or action == "ra" or action == "rs" or action == "rd" or action == "rspacebar" or action == "rshift" then
  362.   saveSavepoint(j+2,1)
  363.   toggleRedstone(action)
  364.  elseif action == "refuel" then
  365.   saveSavepoint(j+2,1)
  366.   turtle.refuel(amount)
  367.  elseif action == "wait" then
  368.   saveSavepoint(j+2,1)
  369.   sleep(amount)
  370.  else
  371.   saveSavepoint(j+2,1)
  372.   loadstring(action())
  373.  end
  374. end
  375.  
  376. function toggleRedstone(side)
  377.  if side == "rw" then side = "front"
  378.  elseif side == "ra" then side = "left"
  379.  elseif side == "rs" then side = "back"
  380.  elseif side == "rd" then side = "right"
  381.  elseif side == "rspacebar" then side = "top"
  382.  elseif side == "rshift" then side = "bottom" end
  383.  redstone.setOutput(side, not redstone.getOutput(side))
  384. end
  385.  
  386.  
  387. -- CREATE NEW ROUTE
  388.  
  389.  
  390. function createNewRoute()
  391.  local liveTracking = false
  392.  local input = ""
  393.  for i=1, countArray(newroute) do
  394.   newroute[i] = nil
  395.  end
  396.  resetRoute()
  397.  clearScreen()
  398.  
  399. -- MENU SCREENS
  400.  
  401.  local selectedmenu = 0
  402.  while true do
  403.   clearScreen()
  404.   if selectedmenu == 0 then
  405.    drawHeader("Create a new route", 1)
  406.    term.setCursorPos(1,3)
  407.    print[[  1 -- Movement
  408.   2 -- Standard Actions
  409.   3 -- Add a program
  410.   4 -- Overview Screen
  411.   5 -- Toggle Live Tracking
  412.   6 -- Add own command
  413.  
  414.   ENTER -- Finish and Save
  415.   Left STRG -- EXIT]]
  416.    term.write("  Live Tracking ")
  417.    if liveTracking then print("enabled") else print("disabled") end
  418.  
  419.   elseif selectedmenu == 1 then
  420.    drawHeader("Movement", 1)
  421.    term.setCursorPos(1,3)
  422.    print[[  W & S -- Forward & Back
  423.   A & D -- Turn Left & Turn Right
  424.   SPACE BAR -- Up
  425.   Left SHIFT -- Down
  426.   R -- Refuel
  427.  
  428.   Left STRG -- Back]]
  429.  
  430.   elseif selectedmenu == 2 then
  431.    drawHeader("Actions", 1)
  432.    term.setCursorPos(1,3)
  433.    print[[  Q -- Suck
  434.   E -- Drop
  435.   Y -- Attack
  436.   X -- Redstone
  437.   C -- Select Slot
  438.   W -- Wait
  439.  
  440.   Left STRG -- Back]]
  441.   end
  442.  
  443.  
  444. -- INPUT
  445.  
  446.   local id, key = os.pullEvent("key")
  447.   input = transfer(key)
  448.   sleep(0.1)
  449.   clearScreen()
  450.  
  451. -- MENU 0
  452.  
  453.   if selectedmenu == 0 then
  454.    if input == "enter" then
  455.     print("This route has " .. #newroute/2 .. " actions.")
  456.     print("How do you want to name the route?")
  457.     local name = read()
  458.     for i=1, countArray(newroute) do
  459.      route[i] = newroute[i]
  460.     end
  461.     saveRoute(name)
  462.     break
  463.    elseif input == "strg" then
  464.     break
  465.    end
  466.   clearScreen()
  467.  
  468.  
  469.  
  470. -- MENU 1
  471.  
  472.   elseif selectedmenu == 1 then
  473.    if input == "strg" then
  474.     selectedmenu = 0
  475.    elseif input == "w" then
  476.     print("How far should the turlte move forward?")
  477.     local far = tonumber(read())
  478.     if far > 0 then
  479.      table.insert(newroute, "w")
  480.      table.insert(newroute, far)
  481.      if liveTracking then makeAction(0,"w", far) end
  482.     end
  483.  
  484.    elseif input == "a" then
  485.     table.insert(newroute, "a")
  486.      table.insert(newroute, "0")
  487.     if liveTracking then makeAction(0,"a",0) end
  488.  
  489.    elseif input == "s" then
  490.     print("How far should the turlte move backwards?")
  491.     local far = tonumber(read())
  492.     if far > 0 then
  493.      table.insert(newroute, "s")
  494.      table.insert(newroute, far)
  495.      if liveTracking then makeAction(0,"s", far) end
  496.     end
  497.  
  498.    elseif input == "d" then
  499.     table.insert(newroute, "d")
  500.     table.insert(newroute, "0")
  501.     if liveTracking then makeAction(0,"d", 0) end
  502.  
  503.    elseif input == "spacebar" then
  504.     print("How far should the turlte move up?")
  505.     local far = tonumber(read())
  506.     if far > 0 then
  507.      table.insert(newroute, "spacebar")
  508.      table.insert(newroute, far)
  509.      if liveTracking then makeAction(0,"spacebar", far) end
  510.     end
  511.  
  512.    elseif input == "shift" then
  513.     print("How far should the turlte move down?")
  514.     local far = tonumber(read())
  515.     if far > 0 then
  516.      table.insert(newroute, "shift")
  517.      table.insert(newroute, far)
  518.      if liveTracking then makeAction(0,"shift", far) end
  519.     end
  520.    
  521.    elseif input == "refuel" then
  522.     print("How many items should be used to refuel the turtle?")
  523.     local amount = tonumber(read())
  524.     if amount < 0 then
  525.      amount = 1
  526.     elseif amount > 64 then
  527.      amount = 64
  528.     end
  529.     table.insert(newroute, "refuel")
  530.     table.insert(newroute, amount)
  531.     if liveTracking then
  532.      turtle.refuel(amount)
  533.     end
  534.    end
  535.  
  536. -- MENU 2
  537.  
  538.   elseif selectedmenu == 2 then
  539.    if input == "strg" then
  540.     selectedmenu = 0
  541.    elseif input == "suck" then
  542.     print[[  On which side should the turtle suck items out?
  543.   W -- in front
  544.   SPACE BAR -- above
  545.   SHIFT -- below]]
  546.     local id, key = os.pullEvent("key")
  547.     local side = transfer(key)
  548.     if side == "spacebar" then
  549.      table.insert(newroute, "suckUp")
  550.      if liveTracking then makeAction(0,"suckUp","0") end
  551.     elseif side == "shift" then
  552.      table.insert(newroute, "suckDown")
  553.      if liveTracking then makeAction(0,"suckDown","0") end
  554.     else
  555.      table.insert(newroute, "suckFront")
  556.      if liveTracking then makeAction(0,"suckFront","0") end
  557.     end
  558.     table.insert(newroute, "0")
  559.  
  560.    elseif input == "drop" then
  561.     print[[On which side should the turtle drop items into?
  562.   W -- in front
  563.   SPACE BAR -- above
  564.   SHIFT -- below]]
  565.     local id, key = os.pullEvent("key")
  566.     local side = transfer(key)
  567.     print("How many items should be dropped?")
  568.     sleep(0.1)
  569.     local amount = tonumber(read())
  570.     if amount < 0 or amount > 64 then
  571.      amount = 64
  572.     end
  573.     if side == "spacebar" then
  574.      table.insert(newroute, "dropUp")
  575.      table.insert(newroute, amount)
  576.      if liveTracking then makeAction(0,"dropUp", amount) end
  577.     elseif side == "shift" then
  578.      table.insert(newroute, "dropDown")
  579.      table.insert(newroute, amount)
  580.      if liveTracking then makeAction(0,"dropDown", amount) end
  581.     else
  582.      table.insert(newroute, "dropFront")
  583.      table.insert(newroute, amount)
  584.      if liveTracking then makeAction(0,"dropFront", amount) end
  585.     end
  586.  
  587.    elseif input == "select" then
  588.     print("Which slot should the turtle select?")
  589.     local slot = tonumber(read())
  590.     if slot < 1 or slot > 16 then
  591.      slot = 1
  592.     end
  593.     table.insert(newroute, "select")
  594.     table.insert(newroute, slot)
  595.     if liveTracking then makeAction(0,"select", slot) end
  596.    
  597.    elseif input == "attack" then
  598.     table.insert(newroute, "attack")
  599.     table.insert(newroute, "0")
  600.     if liveTracking then makeAction(0,"attack",1) end
  601.  
  602.    elseif input == "redstone" then
  603.     print[[On which side a redstone signal be toggled on or off?
  604. W -- in front
  605. A -- on the left
  606. S -- on the back
  607. D -- on the right
  608. SPACE BAR -- above
  609. SHIFT -- below]]
  610.  
  611.     local id, key = os.pullEvent("key")
  612.     local side = transfer(key)
  613.     if side == "w" or side == "a" or side == "s" or side == "d" or side == "spacebar" or side == "shift" then
  614.      side = "r" .. side
  615.     end
  616.     table.insert(newroute, side)
  617.     table.insert(newroute, "0")
  618.     if liveTracking  then toggleRedstone(side) end    
  619.    elseif input == "strg" then
  620.     selectmenu = 0
  621.    elseif input == "w" then
  622.     print("How many seconds should the turtle wait?")
  623.     local time = math.floor(tonumber(read()))
  624.     if time < 0 then
  625.      slot = 1
  626.     end
  627.     table.insert(newroute, "wait")
  628.     table.insert(newroute, time)
  629.    end
  630.   end --end of selectedmenu
  631.  
  632. -- GLOBAL MENU
  633.  
  634.   if input == "1" then
  635.    selectedmenu = 1
  636.   elseif input == "2" then
  637.    selectedmenu = 2
  638.   elseif input == "3" then
  639.    selectRoute()
  640.    if runningRoute == "" then else
  641.     for i=1, countArray(route),2 do
  642.      table.insert(newroute, route[i])
  643.      table.insert(newroute, route[i+1])
  644.      if liveTracking then makeAction(0,route[i],route[i+1]) end
  645.     end
  646.     resetRoute()
  647.     runningRoute = ""
  648.    end
  649.    selectmenu = 0
  650.   elseif input == "4" then
  651.    overviewScreen()
  652.    elseif input == "5" then
  653.    liveTracking = not liveTracking
  654.   elseif input == "6" then
  655.    print("Tipe in the command:")
  656.    local owncommand = read()
  657.    if owncommand == "" then else
  658.     table.insert(newroute, owncommand)
  659.     table.insert(newroute, "0")
  660.     if liveTracking then makeAction(0,owncommand,"0") end
  661.    end
  662.   end
  663.  end --end of while
  664.  clearScreen()
  665.  saveSavepoint(0,0)
  666. end -- end of function
  667.  
  668.  
  669.  
  670. --OVERVIEW SCREEN
  671. function overviewScreen()
  672.  local showScreen = true
  673.  local max = 0
  674.  local lastmax = 0
  675.  local routeBeforeMax = ""
  676.  local routeBeforeMaxPlus = ""
  677.  while showScreen do
  678.   clearScreen()
  679.   print("Last eight actions:")
  680.   for i=15,1,-2 do
  681.    max = countArray(newroute)
  682.    if max - i > 0 then
  683.     beforeMax = max-(i-1)
  684.     routeBeforeMax = newroute[beforeMax]
  685.     routeBeforeMaxPlus = newroute[max-i]
  686.     if beforeMax/2 < 10 then
  687.      term.write(beforeMax/2 .. "  | ")
  688.     elseif beforeMax/2 < 100 then
  689.      term.write(beforeMax/2 .. " | ")
  690.     elseif beforeMax/2 < 1000 then
  691.      term.write(beforeMax/2 .. "| ")
  692.     elseif beforeMax/2 < 10000 then
  693.      term.write(beforeMax/2 .. " ")
  694.     end
  695.     if routeBeforeMaxPlus == "w" then
  696.      print("Forward: " .. routeBeforeMax)
  697.     elseif routeBeforeMaxPlus == "a" then
  698.      print("Turn Left")
  699.     elseif routeBeforeMaxPlus == "s" then
  700.      print("Back: " .. routeBeforeMax)
  701.     elseif routeBeforeMaxPlus == "d" then
  702.      print("Turn Right")
  703.     elseif routeBeforeMaxPlus == "spacebar" then
  704.      print("Up: " .. routeBeforeMax)
  705.     elseif routeBeforeMaxPlus == "shift" then
  706.      print("Down: " .. routeBeforeMax)
  707.     elseif routeBeforeMaxPlus == "suckUp" then
  708.      print("Suck: Above")
  709.     elseif routeBeforeMaxPlus == "suckDown" then
  710.      print("Suck: Below")
  711.     elseif routeBeforeMaxPlus == "suckFront" then
  712.      print("Suck: Front")
  713.     elseif routeBeforeMaxPlus == "dropUp" then
  714.      print("Drop: Up: Amount of Items: " .. routeBeforeMax)
  715.     elseif routeBeforeMaxPlus == "dropDown" then
  716.      print("Drop: Down: Amount of Items: " .. routeBeforeMax)
  717.     elseif routeBeforeMaxPlus == "dropFront" then
  718.      print("Drop: Front: Amount of Items: " .. routeBeforeMax)
  719.     elseif routeBeforeMaxPlus == "refuel" then
  720.      print("Refuel   Amount of Items: " .. routeBeforeMax)
  721.     elseif routeBeforeMaxPlus == "attack" then
  722.      print("Attack")
  723.     elseif routeBeforeMaxPlus == "select" then
  724.      print("Select Slot: " ..routeBeforeMax)
  725.     elseif routeBeforeMaxPlus == "rw" then
  726.      print("Toggle Redstone Output: Front")
  727.     elseif routeBeforeMaxPlus == "ra" then
  728.      print("Toggle Redstone Output: Left")
  729.     elseif routeBeforeMaxPlus == "rs" then
  730.      print("Toggle Redstone Output: Back")
  731.     elseif routeBeforeMaxPlus == "rd" then
  732.      print("Toggle Redstone Output: Right")
  733.     elseif routeBeforeMaxPlus == "rspacebar" then
  734.      print("Toggle Redstone Output: Above")
  735.     elseif routeBeforeMaxPlus == "rshift" then
  736.      print("Toggle Redstone Output: Below")
  737.     elseif routeBeforeMaxPlus == "wait" then
  738.      print("Wait: " .. routeBeforeMax)
  739.     elseif routeBeforeMaxPlus then
  740.      print("Command: " .. routeBeforeMaxPlus)
  741.     end
  742.    end
  743.   end
  744.   print("")
  745.   print("Any Key -- Next Action")
  746.   print("BACKSPACE -- Delete Last Action")
  747.   sleep(0.2)
  748.   local id, key = os.pullEvent("key")
  749.   if key == 14 then
  750.    if countArray(newroute) > 1 then
  751.     table.remove(newroute)
  752.     local last = table.remove(newroute)
  753.     if last == "rw" or last == "ra" or last == "rs" or last == "rd" or last == "rspacebar" or last == "rshift" then
  754.      toggleRedstone(last)
  755.     end
  756.    end
  757.   elseif key == 1 then
  758.   else
  759.    showScreen = false
  760.   end
  761.  end
  762. end
  763.  
  764.  
  765. -- START ROUTE
  766.  
  767. function runRoute()
  768.  clearScreen()
  769.  local max = countArray(route)
  770.  while true do
  771.   for j=currentPoint,max,2 do
  772.    makeAction(j,route[j],route[j+1])
  773.    currentStepPoint = 1
  774.   end
  775.   currentPoint = 1
  776.   saveSavepoint(1,1)
  777.  end
  778.  runningRoute = ""
  779.  saveSavepoint(0,0)
  780. end
  781.  
  782. function selectRoute()
  783.  local showRoutes = true
  784.  local numberroute = 1
  785.  runningRoute = ""
  786.  clearScreen()
  787.  resetRoute()
  788.  
  789.  if countArray(listOfRoutes) == 0 then
  790.   printCentered("No Routes Set!",5)
  791.   showRoutes = false
  792.   sleep(2)
  793.  end
  794.  
  795.  while showRoutes do
  796.   clearScreen()
  797.   print[[   W -- Next Route
  798.    S -- Last Route
  799.    D & ENTER -- Start Selected Route
  800.    A & BACKSPACE -- Return To Main Menu]]  
  801.   printCentered(numberroute .. "/".. countArray(listOfRoutes), 7)
  802.   printCentered(tostring(listOfRoutes[numberroute]) ,8)
  803.   loadRoute(listOfRoutes[numberroute])
  804.   printCentered("Actions: " .. countArray(route)/2,9)
  805.  
  806.   local id, key = os.pullEvent("key")
  807.   if key == 208 or key == 31 then
  808.    numberroute = numberroute - 1
  809.   end
  810.   if key == 200 or key == 17 then
  811.    numberroute = numberroute + 1
  812.   end
  813.   if key == 14 or key == 30 then
  814.     runningRoute = ""
  815.     showRoutes = false
  816.   end
  817.   if numberroute == 0 then
  818.    numberroute = countArray(listOfRoutes)
  819.   end
  820.   if numberroute > countArray(listOfRoutes) then
  821.    numberroute = 1
  822.   end
  823.   if key == 28 or key == 32 then
  824.    runningRoute = listOfRoutes[numberroute]
  825.    showRoutes = false
  826.   end
  827.  end
  828. end
  829.  
  830. function startRoute()
  831.  selectRoute()
  832.  if runningRoute == "" then else
  833.   currentPoint = 1
  834.   currentStepPoint = 1
  835.   runRoute()
  836.  end
  837. end
  838.  
  839.  
  840. loadListOfRoutes()
  841. if fs.exists("Savepoint") then
  842.  loadSavepoint()
  843.  if currentPoint > 0 then
  844.   loadRoute(runningRoute)
  845.   runRoute()
  846.   saveSavepoint(0,0)
  847.  end
  848. end
  849. runMenu()
  850. sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment