Advertisement
Guest User

redoPosition

a guest
Apr 24th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local stringQuestionAsked = "Do you want to?"
  2. local choices = {"Yes I do", "No I don't"}
  3. local chosenOne
  4. local highlighted = 1
  5. local x,y = term.getSize()
  6. function writeChoices()                         --writes the choices down made for the menu
  7.     for i=1,#choices do
  8.         if i == highlighted then
  9.             term.setCursorPos(((x/2)-(("<| "..choices[i].." |>"):len()/2)),i + 2)
  10.             term.clearLine()
  11.             term.write("<| "..choices[i].." |>")
  12.         else
  13.             term.setCursorPos(((x/2)-(choices[i]:len()/2)),i + 2)
  14.             term.clearLine()
  15.             term.write(choices[i])
  16.         end
  17.     end
  18. end
  19.  
  20. function menuSelection()                        --waits for key input and changes the highlighted menuElemnt
  21.     while true do
  22.         writeChoices()
  23.         local event, key = os.pullEvent( "key" )
  24.         if key == keys.down then
  25.             highlighted = highlighted + 1
  26.         end
  27.         if key == keys.up then
  28.             highlighted = highlighted - 1
  29.         end
  30.         if key == keys.enter then
  31.             chosenOne = choices[highlighted]
  32.             break
  33.         end
  34.         if highlighted == 0 then
  35.             highlighted = #choices
  36.         end
  37.         if highlighted == #choices + 1 then
  38.             highlighted = 1
  39.         end
  40.     end
  41. end
  42.  
  43. function Menu()                                 --Creates a menu
  44.     term.clear()
  45.     term.setCursorPos(math.ceil((x/2)-(stringQuestionAsked:len()/2)),1)
  46.     term.write(stringQuestionAsked)
  47.     menuSelection()
  48. end
  49.  
  50. term.clear()
  51. term.setCursorPos(1,1)
  52. print("Are you sure you want to delete the Positional data of the turtle. This will mean you will have to replace it in a new Starting Position and your number of holes dug will be reset.")
  53. os.sleep(8)
  54. Menu()
  55. if chosenOne == choices[1] then
  56.     fs.delete("Data/".."turtleDataFile")
  57.     fs.delete("Data/".."turtleActivity")
  58.     fs.delete("Data/".."turtleModemFile")
  59.    
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement