Advertisement
subzero22

selection

Sep 8th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local termWidth, termHeight = term.getSize()
  2. local selectedItem = 10
  3. local onMainMenu = true
  4.  
  5. function Choice1()
  6.  term.clear()
  7.  
  8.  print("CHOICE 1")
  9.  sleep(1)
  10. end
  11.  
  12. function Choice2()
  13. term.clear()
  14.  
  15. print("CHOICE 2")
  16. sleep(1)
  17. end
  18.  
  19. function Choice3()
  20. term.clear()
  21.  
  22. print("CHOICE 2")
  23. sleep(1)
  24. end
  25. function Choice4()
  26. term.clear()
  27.  
  28. print("CHOICE 2")
  29. sleep(1)
  30. end
  31. function Choice5()
  32. term.clear()
  33.  
  34. print("CHOICE 2")
  35. sleep(1)
  36. end
  37. function Choice6()
  38. term.clear()
  39.  
  40. print("CHOICE 2")
  41. sleep(1)
  42. end
  43. function Choice7()
  44. term.clear()
  45.  
  46. print("CHOICE 2")
  47. sleep(1)
  48. end
  49. function Choice8()
  50. term.clear()
  51.  
  52. print("CHOICE 2")
  53. sleep(1)
  54. end
  55. function Choice9()
  56. term.clear()
  57.  
  58. print("CHOICE 2")
  59. sleep(1)
  60. end
  61. function Choice10()
  62. term.clear()
  63.  
  64. print("CHOICE 2")
  65. sleep(1)
  66. end
  67. function Choice11()
  68. term.clear()
  69.  
  70. print("CHOICE 2")
  71. sleep(1)
  72. end
  73. function Choice12()
  74. term.clear()
  75.  
  76. print("CHOICE 2")
  77. sleep(1)
  78. end
  79. function Choice13()
  80. term.clear()
  81.  
  82. print("CHOICE 2")
  83. sleep(1)
  84. end
  85. function Choice14()
  86. term.clear()
  87.  
  88. print("CHOICE 2")
  89. sleep(1)
  90. end
  91. function Choice15()
  92. term.clear()
  93.  
  94. print("CHOICE 2")
  95. sleep(1)
  96. end
  97. function Choice16()
  98. term.clear()
  99.  
  100. print("CHOICE 2")
  101. sleep(1)
  102. end
  103. function Choice17()
  104. term.clear()
  105.  
  106. print("CHOICE 2")
  107. sleep(1)
  108. end
  109. function Choice18()
  110. term.clear()
  111.  
  112. print("CHOICE 2")
  113. sleep(1)
  114. end
  115. function Choice19()
  116. term.clear()
  117.  
  118. print("CHOICE 2")
  119. sleep(1)
  120. end
  121. function Choice20()
  122. term.clear()
  123.  
  124. print("CHOICE 2")
  125. sleep(1)
  126. end
  127. function Exit()
  128.  onMainMenu = false
  129. end
  130.  
  131. mainMenu = {
  132. [1] = { text = "Choice 1", handler = Choice1 },
  133. [2] = { text = "Choice 2", handler = Choice2 },
  134. [3] = { text = "Exit", handler = Exit },
  135. [4] = { text = "Choice 3", handler = Choice3 },
  136. [5] = { text = "Choice 4", handler = Choice4 },
  137. [6] = { text = "Choice 5", handler = Choice5 },
  138. [7] = { text = "Choice 6", handler = Choice6 },
  139. [8] = { text = "Choice 7", handler = Choice7 },
  140. [9] = { text = "Choice 8", handler = Choice8 },
  141. [10] = { text = "Choice 9", handler = Choice9 },
  142. [11] = { text = "Choice 10", handler = Choice10 },
  143. [12] = { text = "Choice 11", handler = Choice11 },
  144. [13] = { text = "Choice 12", handler = Choice12 },
  145. [14] = { text = "Choice 13", handler = Choice13 },
  146. [15] = { text = "Choice 14", handler = Choice14 },
  147. [16] = { text = "Choice 15", handler = Choice15 },
  148. [17] = { text = "Choice 16", handler = Choice16 },
  149. [18] = { text = "Choice 17", handler = Choice17 },
  150. [19] = { text = "Choice 18", handler = Choice18 },
  151. [20] = { text = "Choice 19", handler = Choice19 },
  152. [21] = { text = "Choice 20", handler = Choice20 },
  153. }
  154.  
  155. function printMenu( menu )
  156.  for i=1,#menu do
  157.   if i == selectedItem then
  158.    term.clear()
  159.    term.setCursorPos(1,1)
  160.    print(">> "..menu[i].text.."  ")
  161.   else
  162.    print("   "..menu[i].text.."  ")
  163.   end
  164.  end
  165. end
  166.  
  167. function onKeyPressed( key, menu )
  168.  if key == 28 then
  169.   onItemSelected(menu)
  170.  elseif key == 200 then
  171.   if selectedItem > 1 then
  172.    selectedItem = selectedItem - 1
  173.   end
  174.  elseif key == 208 then
  175.   if selectedItem < #menu then
  176.    selectedItem = selectedItem + 1
  177.   end
  178.  end
  179. end
  180.  
  181. function onItemSelected( menu )
  182.  menu[selectedItem].handler()
  183. end
  184.  
  185. function main()
  186.  while onMainMenu do
  187.   term.clear()
  188.   term.setCursorPos(1,1)
  189.   printMenu(mainMenu)
  190.   event, key = os.pullEvent("key")
  191.   onKeyPressed(key,mainMenu)
  192.  end
  193. end
  194.  
  195. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement