soccer16x

Elevator Script

Jan 19th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. --[[ Local Variables ]]--
  2.  
  3. local termWidth, termHeight = term.getSize()
  4. local selectedItem = 1
  5. local inMainMenu = true
  6.  
  7. --[[ Elevator Movement Methods ]]--
  8.  
  9. function up()
  10. --shouldn't be needed but in case system needs reset
  11. --indiv. level computers handle going back
  12. redstone.setOutput("left",true)
  13. sleep(0.2)
  14. redstone.setOutput("left",false)
  15. end
  16.  
  17. function down()
  18. redstone.setOutput("back",true)
  19. sleep(0.2)
  20. rs.setOutput("back",false)
  21. end
  22.  
  23. function downMainFloor()
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. term.setTextColor(colors.purple)
  27. print("Calling Elevator")
  28. for i = 1,6 do
  29. down()
  30. end
  31. print("Elevator has arrived, you have precisely 3 seconds to get on.")
  32. sleep(3)
  33. end
  34.  
  35. --[[ Menu Methods ]]--
  36.  
  37. function level45()
  38. downMainFloor()
  39. for i = 1, 2 do
  40. down()
  41. end
  42. end
  43.  
  44. function level25()
  45. downMainFloor()
  46. for i = 1, 2 do
  47. down()
  48. end
  49. end
  50.  
  51. function level10()
  52. downMainFloor()
  53. for i = 1, 2 do
  54. down()
  55. end
  56. end
  57.  
  58. function exit()
  59. inMainMenu = false
  60. end
  61.  
  62. --[[ Menu Definitions ]]--
  63.  
  64. mainMenu = {
  65. [1] = { text = "Level 10:Best for Diamonds", handler = level10 } ,
  66. [2] = { text = "Level 25:Best for Lead/Silver" , handler = level25 } ,
  67. [3] = { text = "Level 45:Best for Copper" , handler = level45 } ,
  68. [4] = { text = "Exit" , handler = exit }
  69. }
  70.  
  71. --[[ Printing Methods ]]--
  72.  
  73. function printMenu( mainMenu )
  74. for i = 1,#mainMenu do
  75. if i == selectedItem then
  76. term.setTextColor(colors.red)
  77. print(mainMenu[i].text)
  78. else
  79. term.setTextColor(colors.white)
  80. print(mainMenu[i].text)
  81. end
  82. end
  83. end
  84.  
  85. --[[ Handler Methods ]]--
  86.  
  87. function onKeyPressed( key, mainMenu )
  88. if key == keys.enter then
  89. onItemSelected(mainMenu)
  90. elseif key == keys.up then
  91. if selectedItem > 1 then
  92. selectedItem = selectedItem - 1
  93. end
  94. elseif key == keys.down then
  95. if selectedItem < #mainMenu then
  96. selectedItem = selectedItem + 1
  97. end
  98. end
  99. end
  100.  
  101. --[[ Main Methods ]]--
  102.  
  103. function main()
  104. while inMainMenu do
  105. term.clear()
  106. term.setCursorPos(1,1)
  107. term.setTextColor(colors.white)
  108. printMenu(mainMain)
  109.  
  110. event,key = os.pullEvent("key")
  111. onKeyPressed(key,menu)
  112. end
  113. end
  114.  
  115. main()
Advertisement
Add Comment
Please, Sign In to add comment