ravneravn

cc academy tutorial

Feb 2nd, 2015
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Basic menus:
  2. -- Creating programs
  3. -- Text
  4. -- Debugging
  5. -- Variables
  6. --
  7. --
  8.  
  9. -- Advanced menus:
  10. -- Pull event
  11. -- input
  12. -- loop
  13. -- functions
  14. -- redstone signal
  15.  
  16.  
  17. local width, length = term.getSize()
  18.  
  19. function centerText(text,yCursor)
  20. local xPos =(width-string.len(text))/2
  21. term.setCursorPos(xPos, yCursor)
  22. write(text)
  23. end
  24.  
  25.  
  26.  
  27.  
  28. -------------------------
  29. -- MAIN MENU
  30.  
  31.  
  32. function nothingMenu()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. print("Nothing here yet")
  36.  
  37. centerText("Click to go to menu", length-1)
  38. event = os.pullEvent("mouse_click")
  39. basicMenu()
  40. end
  41.  
  42.  
  43. function basicMenu()
  44. term.clear()
  45. centerText("Select subject", 1)
  46. centerText("Creating programs",5)
  47. centerText("Printing text", 7)
  48. centerText("Variables", 9)
  49. centerText("Another one", 11)
  50. centerText("Another one", 13)
  51. centerText("Reading errors", 15)
  52.  
  53. local event, button, clickX, clickY = os.pullEvent("mouse_click")
  54. if clickY == 5 then
  55. fileMenu()
  56. elseif clickY == 7 then
  57. textMenu()
  58. elseif clickY == 9 then
  59. nothingMenu()
  60. elseif clickY == 11 then
  61. nothingMenu()
  62. elseif clickY == 13 then
  63. nothingMenu()
  64. elseif clickY == 15 then
  65. debugMenu()
  66. end
  67.  
  68. end
  69.  
  70. function fileMenu()
  71. term.clear()
  72. term.setCursorPos(1,1)
  73. print("To edit a file type edit [file name] without the square brackets. This will open the file. If the file doesn't exist yet, a file with the chosen name will be made.")
  74. print(" ")
  75. print("To save a file hit ctrl to bring up the menu. You can chose using the arrow keys and select by hitting enter.")
  76. print(" ")
  77. print("To run a program, enter the file name and hit enter.")
  78.  
  79. centerText("Right click to go back", length-1)
  80. centerText("Left clcik to continue", length)
  81.  
  82. local event, button = os.pullEvent("mouse_click")
  83. if button == 1 then
  84. fileMenu2()
  85. elseif button == 2 then
  86. basicMenu()
  87. end
  88. end
  89.  
  90. function fileMenu2()
  91. term.clear()
  92. term.setCursorPos(1,1)
  93. print("To see available programs type 'ls' at a start screen")
  94. print(" ")
  95. print("To exit a program hold ctrl+t, or ctrl+r to reboot the computer")
  96. print(" ")
  97. print("When editing a file each line will count as one action in the program")
  98. print(" ")
  99. print("Anything written on a line starting with ''--'' will not be considered code.")
  100. print(" ")
  101. print("Command words are case sensitive")
  102. print(" ")
  103. print("Using the sleep() command will make the program wait a number of seconds specified by a number in the brackets. sleep(2) will make it wait two seconds")
  104.  
  105. centerText("Right click to go back", length-1)
  106. centerText("left click for menu", length)
  107.  
  108. local event, button = os.pullEvent("mouse_click")
  109. if button == 1 then
  110. basicMenu()
  111. elseif button == 2 then
  112. fileMenu()
  113. end
  114. end
  115.  
  116.  
  117. function textMenu()
  118. term.clear()
  119. term.setCursorPos(1,1)
  120. print("To make the program print a text use the command print(''your text''). It will look like this:")
  121. print(" ")
  122. print("your text")
  123. centerText("Right click for menu", length-1)
  124. centerText("Left clik to continue", length)
  125.  
  126. local event, button = os.pullEvent("mouse_click")
  127. if button == 1 then
  128. term.clear()
  129. term.setCursorPos(1,1)
  130. print("You can also make the text roll in slowly by using the command textutils.slowPrint(''your text''). It will look like this:")
  131. print(" ")
  132. sleep(3)
  133. textutils.slowPrint("your text")
  134. centerText("Right click for menu", length-1)
  135. centerText("Left clik to continue", length)
  136. elseif button == 2 then
  137. basicMenu()
  138. end
  139.  
  140. local event, button = os.pullEvent("mouse_click")
  141. if button == 1 then
  142. term.clear()
  143. term.setCursorPos(1,1)
  144. print("Or you can have the text centered by setting the cursor position: term.setCursorPos(x,y). Like this:")
  145. centerText("your text", length-10)
  146. elseif button == 2 then
  147. basicMenu()
  148. end
  149.  
  150. while true do
  151. centerText("Right click for menu", length-1)
  152. local event, button = os.pullEvent("mouse_click")
  153. if button == 2 then
  154. basicMenu()
  155. end
  156. end
  157. end
  158.  
  159.  
  160. function debugMenu()
  161. term.clear()
  162. term.setCursorPos(1,1)
  163.  
  164. print("If you make a mistake in a code you will get an error when running the program.")
  165. print("It will show the following information")
  166. print("bios:336: [string ''program name'']:line the error occurs in: Type of error")
  167. print(" ")
  168. print("The name of the program you're trying to run, what line the error occurs in and what type of error is occuring.")
  169.  
  170. centerText("Click to continue", length-1)
  171. local event, button = os.pullEvent("mouse_click")
  172. term.clear()
  173. term.setCursorPos(1,1)
  174.  
  175. centerText("Common errors:", 1)
  176. term.setCursorPos(1,2)
  177. print(" ")
  178. print("bios:366:[string ''Test'']:5: unfinished string")
  179. print(" ")
  180. print("There's an unfinished string in line 5 of the program Test")
  181. print("To fix, add '' at the end of your string.")
  182.  
  183. centerText("Click to continue", length-1)
  184. local event, button = os.pullEvent("mouse_click")
  185. term.clear()
  186. term.setCursorPos(1,1)
  187.  
  188. print("bios:366: [string ''test'']:3: ')' expected")
  189. print(" ")
  190. print("You haven't finished a command in line 3, and the program is expecting a ')' at the end")
  191.  
  192. centerText("Click to continue", length-1)
  193. local event, button = os.pullEvent("mouse_click")
  194. term.clear()
  195. term.setCursorPos(1,1)
  196.  
  197. print("bios:366: [string ''test'']:6: unexpected symbol")
  198. print(" ")
  199. print("You have used an unexpected symbol in line 6.")
  200.  
  201. centerText("Click to continue", length-1)
  202. local event, button = os.pullEvent("mouse_click")
  203. term.clear()
  204. term.setCursorPos(1,1)
  205.  
  206. print("bios:366: [string ''test'']:6: 'end' expected (to close 'if' at line 4)")
  207. print(" ")
  208. print("You have an unfinished if loop starting at line 4 and ending at line 6. You need to add an 'end'.")
  209.  
  210. centerText(" Right click to go to menu", length-1)
  211. while true do
  212. local event, button = os.pullEvent("mouse_click")
  213. if button == 2 then
  214. mainMenu()
  215. end
  216. end
  217. end
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227. function mainMenu()
  228. term.clear()
  229. centerText("Select difficulty",1)
  230. centerText("Basic", 5)
  231. centerText("Advanced", 9)
  232.  
  233. local event, button, clickX, clickY = os.pullEvent("mouse_click")
  234. if clickY >= 4 and clickY <=6 then
  235. basicMenu()
  236. elseif clickY >= 8 and cluckY <=10 then
  237. advancedMenu()
  238. end
  239. end
  240.  
  241.  
  242. -- LOOP
  243. mainMenu()
RAW Paste Data