Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.60 KB | None | 0 0
  1. local component = require("component")
  2. local fs = require("filesystem")
  3. local internet = require("internet")
  4. local process = require("process")
  5. local event = require("event")
  6. local keyboard = require("keyboard")
  7. local shell = require("shell")
  8. local term = require("term")
  9. local text = require("text")
  10. local unicode = require("unicode")
  11. local sides = require("sides")
  12. local colors=require("colors")
  13.  
  14.  
  15. local ul = {0x250C, 0x2554}
  16. local ur = {0x2510, 0x2557}
  17. local ll = {0x2514, 0x255A}
  18. local lr = {0x2518, 0x255D}
  19. local sl = {0x2502, 0x2551}
  20. local al = {0x2500, 0x2550}
  21.  
  22. function getCh()
  23. return (select(4, event.pull("key_down")))
  24. end
  25.  
  26.  
  27. -- BaseLine Variables
  28. CurrentChapter = 1
  29. CurrentSection = 1
  30. ChapterTitles = {
  31. "How to Create a Program",
  32. "How to Display and clear Text",
  33. "How to Use and Display Variables",
  34. "How to get User Input",
  35. "How to use IF statements",
  36. "How to use loops",
  37. "How to use redstone",
  38. "How to use redpower bundles",
  39. "How to use events",
  40. "How to use functions",
  41. "Extra Tips and Extra Functions"
  42. }
  43.  
  44. Chapter = {
  45. [1] = {
  46. "Key Points in this Chapter:\n\n1. Learning how to create a program.\n2. Learning how to save that program.\n3. Learning how to run that program.",
  47. "1.1 - Learning how to create a program.\n\nOk so first things first right? We gotta learn how to create our first program. Creating a program is very simple in OC.\n\nedit programname\n\nedit means we want to create or edit program, and programname is the name of the program we wish to edit or create.",
  48. "1.2 - Learning how to save that program.\n\nSo now your inside the editing feature of OC and you can move around almost like a notepad. We want to press the [Control] key which will bring up a menu at the bottom of your screen. Pressing CTRL - S [SAVE] will save the program. CTRL - W [EXIT] will exit editing the program.",
  49. "1.3 - Learning how to run that program.\n\nWe've created our little program, but how do we run it? Well thats simple. We type the program name into our terminal and press [ENTER], but remember all things in LUA are case-sensitive. Your program named \"Hello\" is not the same as your program named \"hello\".",
  50. "1.4 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  51. "SIM"
  52. },
  53. [2] = {
  54. "Key Points in this Chapter:\n\n1. How to use print\n2. How to use write\n3. How to clear the screen.\n4. How to use the cursor position.\n5. How to clear a specific line.",
  55. "2.1 - How to use print.\n\nTo show text to the user is a simple task. We do so by the following.\n\nprint (\"Hello User\")\n\nprint means to display the text to the user, and Hello User is the text we wish to display.",
  56. "2.2 - How to use write.\n\nWhen you print text, the program automatically adds a linebreak after your print command, sometimes you may not wish to do this.\n\nwrite (\"Hello\")\nprint (\"User\")\n\nThese two lines would make the exact same appearance as the print line we made previously. The reason is because the write command does not generate a linebreak and we can use this to keep our current position and continue writing on the same line.",
  57. "2.3 - How to clear the screen.\nQuite often you'll want to clear the screen automatically in your program.\n\nterm.clear()\n\nUsing this line we can clear the screen for our user to remove anything we don't want cluttering up the screen.",
  58. "2.4 - How to use the cursor position.\nThe cursor position is a very powerful thing. For example, when you clear the screen, the cursor still stays on it's previous line. Meaning that after you clear the screen, your next print statement very well may appear at the bottom of the screen.",
  59. "2.4 - How to use the cursor position.\nTo remedy this problem we've been given the command.\n\nterm.setCursor(1,1)\n\nThe first 1 in our statment is the horizontal position and the second 1 on our statement is the vertical posistion.",
  60. "2.4 - How to use the cursor position.\nBy using the term.setCursor(1,1) directly after a term.clear(), we can make sure that the next text we show the user appears at the top of his screen.\n\nRemember, lua is case sensitive. term.setCursor(1,1) is not right.",
  61. "2.5 - How to clear a specific line.\nBy using the term.setCursor we can create some pretty nifty tricks, like reprinting over lines already on the screen, or even clearing a certain line and printing something new.",
  62. "2.5 - How to clear a specific line.\nterm.setCursor(1,1)\nprint (\"You won't see this\")\nterm.setCursor(1,1)\nterm.clearLine()\nprint (\"Hello User\")\n\nWe used the term.clearLine() to remove the line at 1,1 and then we printed a new line where the old line used to be.",
  63. "2.6 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  64. "SIM"
  65. },
  66. [3] = {
  67. "Key Points in this Chapter:\n\n1. What is a variable\n2. How to use a variable\n3. How to display a variable\n4. How to convert a variable",
  68. "3.1 - What is a variable.\n\nThink of a variable as a container in which you can place text or a number. Using variables allows you to store information and modify it on the fly. Using variables correctly is the key to making a sucessful program.",
  69. "3.2 - How to use a variable.\n\nThe first thing we should almost always do when we want to use a variable in a program is to define the variable. We do this by giving the variable a default piece of data. If we don't define a variable then the variable is considered NIL until it has been set.",
  70. "3.2 - How to use a variable.\n\nA NIL variable can cause lots of problems in your program, if you try to add together 2 variables and one is NIL, you'll get an error, if you try printing a NIL variable you'll get an error.",
  71. "3.2 - How to use a variable.\n\nWe'll be using the variable x from this point onward. Remember that x is different then X in lua.\n\nx = 0\n\nThis defined x to have a default value of 0. You could also do x = \"hello\" if you wanted it to contain text.",
  72. "3.2 - How to use a variable.\n\nA variable will hold it's data until you change it. Therefor x = 0 means that x will be 0 until you tell your program that x is something different.",
  73. "3.2 - How to use a variable.\n\nYou can also set variables as booleans, booleans are true and false.\nx = true\nThis would set x to true, which is different then \"true\". Using booleans gives you 1 more way to define a variable to be used later in your program.",
  74. "3.3 - How to display a variable.\n\nBeing able to show a variable to the user is very important. Who wants to just save the user's name in a variable, but not show it to them during the program? When displaying variables we can use the print or write commands.",
  75. "3.3 - How to display a variable.\nx = 0\nprint (x)\nx = \"Bob\"\nprint (\"Hello\"..x)\n\nYou'll notice in the last line that we used our x variable along with another piece of text. To do so we used .. which tells the program to add the x variable directly after the word Hello. In this syntax that would show the user HelloBob since we didn't add a space ;)",
  76. "3.3 - How to display a variable.\n\nRemember variables are case sensitive, and that variable1 is different then Variable1.\nIf you wanted to place a variable inbetween text you could do.\n\nprint (\"Hello \"..x..\" how are you?\")\n\nThis would print Hello Bob how are you?",
  77. "3.4 - How to convert a variable.\n\nSometimes a variable might need to be converted, this is mainly the case when you want to use the variable as a number, but it's currently a string. For example:\nx = \"0\"\nx = x + 1\n\nThis will not work, as x equals \"0\"",
  78. "3.4 - How to convert a variable.\n\nThe difference between 0 and \"0\" is that one is a number and the other is a string. You can't use the basic math functions on strings. Lua can convert a number to a string automatically but it cannot convert a string to a number automatically.",
  79. "3.4 - How to convert a variable.\n\nx = 0\ny = \"1\"\nWe can't add those together atm, so we need to convert our string to a number so that we can add it to x.\ny = tonumber(y)\nThis converts y to a number (if it can't be converted to a number then y will be NIL)",
  80. "3.4 - How to convert a variable.\n\nNow that we've converted y to a number we can do.\nx = x + y\nThis would make x equal to x(0) + y(1). This means that x is now equal to 1 and y hasn't changed so it's still 1 as well.",
  81. "3.4 - How to convert a variable.\n\nIf we want to add a string to another string, we don't use the math symbols, we simply use ..\nx = \"Hello\"\ny = \"Bob\"\nx = x..y\nThis would make x = \"HelloBob\"",
  82. "3.4 - How to convert a variable.\n\nRemember that Lua can convert a number to a string, but not the other way around. If you always want to be 100% positive what your variables are, use the functions tonumber(x) and tostring(x).",
  83. "3.5 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  84. "SIM"
  85. },
  86. [4] = {
  87. "Key Points in this Chapter:\n\n1. How to get user input",
  88. "4.1 - How to get user input.\n\nWhat's the point of having all these cool variables if your user can't make a variable be something they want? We fix this by allowing the user to input a variable into the program.",
  89. "4.1 - How to get user input.\n\nx = io.read()\nThe io.read() tells the program to stop and wait for user input, when the user presses enter that information is then stored in the variable x and the program continues.\nUser input is always stored as a string, therefor if the user types 1 and presses enter, x will be come \"1\", not 1",
  90. "4.1 - How to get user input.\n\nOnce the user's input is entered into the x variable you can use that variable like you would any other variable. This means if you then wanted to show the user their input you could follow your io.read() line with print(x)",
  91. "4.1 - How to get user input.\n\nBy using the write command before an io.read() we can show text then have the user type after that text.\nwrite(\"Enter Your Name -\"\nname = io.read()\nThis would have the user type their name directly after the - in the write statement.",
  92. "4.2 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  93. "SIM"
  94. },
  95. [5] = {
  96. "Key Points in this Chapter:\n\n1. What is an IF statement\n2. The ELSE statement\n3. The ELSEIF statement\n4. Complex IF's",
  97. "5.1 - What is an IF statement.\n\nWe use IF statements to control the programs direction based on certain criteria that you define. Doing this allows us to do only certain things based on certain conditions.",
  98. "5.1 - What is an IF statement.\n\nif name == \"Bob\" then\nprint (\"Hello Again Bob\")\nend\n\nThe 1st line says, if the variable name is equal to \"Bob\" then enter this IF statement. The next line is the code that will run if name does equal Bob. The 3rd line says to end the IF statement, if the name was not Bob the program would skip to the line directly after end.",
  99. "5.1 - What is an IF statement.\n\nWe have many options in the IF statement, we could do:\nif x >= 1\nRemember we can't do that IF statement if x is a string x = \"1\".\nif name ~= \"Bob\"\nThe ~= option means is not equal too. This if statement would pass if the name was NOT Bob.",
  100. "5.2 - The ELSE statement.\n\nSometimes we want to do 1 thing if our IF statement is true and something else if it's false.\nif name == \"Bob\" then\nprint (\"Hello Bob\")\nelse\nprint(\"Your not Bob\")\nend\n\n",
  101. "5.2 - The ELSE statement.\n\nNotice how their is only 1 end statement as the last line of the entire IF statement. The ELSE line is a part of the current IF statement.",
  102. "5.3 - The ELSEIF statement.\n\nSometimes we want to check for multiple outcomes inside an IF statement, we can achieve this using the ELSEIF statement. The key things to remember is that you still only need 1 end as the last line, because this is 1 full statement, and that you will need to include a then for an ELSEIF.",
  103. "5.3 - The ELSEIF statement.\n\nif name == \"Bob\" then\nprint (\"Hello Bob\")\nelseif name == \"John\" then\nprint (\"Hello John\")\nelse\nprint (\"Hello Other\")\nend",
  104. "5.3 - The ELSEIF statement.\n\nI still included the final else, which tells the program if the name wasn't Bob or John, then do something else. Notice again that there was only a single end as the last line, because this was 1 full statement.",
  105. "5.4 - Complex IF's.\n\nIf's can become very complex depending on your situation. I will show some examples of more complex IF's:\nif name == \"Bob\" and name ~= \"John\" then\nWe are checking the variable twice in 1 if statement by using the AND statement. We could also use the OR statement",
  106. "5.4 - Complex IF's.\n\nYou can also place IF statements inside other IF statements, just make sure you place an END statement at the correct place for each IF statement. Next page is an example of a pretty complex IF statement.",
  107. "5.4 - Complex IF's.\nif name == \"Bob\" then\n if x == 1 then\n print(x)\n else\n print(\"Not 1\")\n end\nprint (\"Hi Bob\")\nelse\nprint (\"Your not Bob\")\nend",
  108. "5.4 - Complex IF's.\nWith precise placement of IF statements you can control the flow of your program to a great degree, this allows you to make sure the user is only seeing what you want them to see at all times.",
  109. "5.5 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  110. "SIM"
  111. },
  112. [6] = {
  113. "Key Points in this Chapter:\n\n1.What is a loop\n2.How to exit a loop\n3.Different kinds of loops",
  114. "6.1 - What is a loop\n\nA loop is a section of code that will continually run until told otherwise. We use these to repeat the same code until we say otherwise.\n\nwhile true do\nend\n\nThis is a while loop that has no exit, it will continually run over and over again until the program crashes.",
  115. "6.2 - How to exit a loop\nSince we don't want our loops to run until they crash we have to give them a way to stop. We do this by using the BREAK command.The break command is mostly placed inside an IF statement as just placing it in the loop itself would break the loop right away.",
  116. "6.2 - How to exit a loop\n\nx = 0\nwhile true do\n x = x + 1\n if x == 10 then\n break\n end\nend\n\nNotice how are while statements have their own end? This would run the loop and continually add 1 to x until x == 10 then it will break out of the loop.",
  117. "6.3 - Different kinds of loops\n\nYou don't always need to use the BREAK command. You can also include a condition in the WHILE statement for how long to run the loop.\n\nx = 0\nwhile x < 10 do\nx = x + 1\nend\n\nWe could also end this early with a BREAK as well.",
  118. "6.3 - Different kinds of loops\n\nHeck we don't even have to use the WHILE statement to create a loop.\n\nfor x = 0, 10, 1 do\nprint (x)\nend\n\nThe first line says - x starts at 0, and continues until 10, increasing by 1 every time we come back to this line.",
  119. "6.3 - Different kinds of loops\n\nSo using the for statement we could do.\n\nx = 5\nfor x, 50, 5 do\nprint (x)\nend\n\nThis would printout 5 then 10 then 15 ect ect until reaching 50.",
  120. "6.4 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  121. "SIM"
  122. },
  123. [7] = {
  124. "Key Points in this Chapter:\n\n1. Turning on and off redstone\n2. Checking and Setting Redstone",
  125. "7.1 - Turning on and off redstone\n\nOne of the greatest features of OC is that your computer can not only receive redstone signals, but it can also send them as well. We have 6 directions to choose from and they are:\ntop, bottom, front, back, left, right",
  126. "7.1 - Turning on and off redstone\n\nWe can control redstone with our computer using 2 basic commands, redstone.getInput(side) and redstone.setOutput(side, boolean).\nWe have to remember to place our sides in quotes though IE \"left\"",
  127. "7.2 - Checking and Setting Redstone\n\nredstone.setOutput(\"back\", true)\nThis tells the computer to turn on the redstone output on the back of the computer. We can replace true with false to turn off the redstone output to the back.",
  128. "7.2 - Checking and Setting Redstone\n\nif redstone.getInput(\"back\") == true then\nprint \"Redstone is on\"\nend\n\nThis would enter the IF statement if their was power running to the back of the computer.",
  129. "7.2 - Checking and Setting Redstone\n\nBy checking and setting different redstone sources while using IF statements we can control multiple things connected to our computer based on the redstone connections.",
  130. "7.3 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  131. "SIM"
  132. },
  133. [8] = {
  134. "Key Points in this Chapter:\n\n1. How to turn on a single color\n2. How to turn off a single color\n3. Using multiple colors\n4. Testing Inputs\n5. Turning off all colors.",
  135. "8.1 - How to turn on a single color\n\nrs.setBundledOutput(\"back\", colors.white)\n\nThis would turn on the white output in the back.",
  136. "8.2 - How to turn off a single color\n\nrs.setBundledOutput(\"back\", rs.getBundledOutput(\"back\") - colors.white)\n\n This would turn off only the color white in the back.",
  137. "8.3 - Using Multiple colors\nUsing multiple colors is much easier when you use the colors.combine colors.subtract functions.",
  138. "8.3 - Using Multiple colors\n\nout = colors.combine(colors.blue, colors.white)\nrs.setBundledOutput(\"back\", out)\n\nThis would turn on blue and white at the back\nout = colors.subtract(out, colors.blue)\nrs.setBundledOutput(\"back\", out)\nThis would turn off blue, but leave white on.",
  139. "8.4 - Testing Inputs\n\nin = rs.getBundledInput(\"back\")\nif colors.test(in, colors.white) == true then\n\nThis would get the current input and store it in the in variable. We then use colors.test on the in variable to see if white is on.",
  140. "8.5 - Turning off all colors\n\nrs.setBundledOutput(\"back\", 0)\n\nSetting the output to 0 is the quickest and most efficient way to turn off all colors at the same time.",
  141. "8.6 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  142. "SIM"
  143. },
  144. [9] = {
  145. "Key Points in this Chapter:\n\n1. What is an event?\n2. How do we check for events\n3. What types of events are there?\n4. Using event loops\n5. WHATS GOING ON!",
  146. "9.1 - What is an event?\n\nAn event can be many things, from redstone to timers, as well as smashing your face on the keyboard. These can all trigger events within a program, and by correctly using the event.pull() command we can make sure that no matter what happens, we'll know about it!",
  147. "9.2 - How do we check for events\n\nevent, param1, param2 = event.pull()\n\nPlacing this line in your code will stop the program until ANY event triggers. So just by pressing a key, you will pass this statement because a keypress is an event",
  148. "9.2 - How do we check for events\n\nThe easiest way to check for an event happening is the IF statement.\n\nif event == \"char\" and param1 == \"q\" then\n This line would trigger if you pressed q on your keyboard.",
  149. "9.3 - What types of events are there\n\nchar - triggers on keypress\nkey - triggers on keypress\ntimer - triggers on a timer running out\nalarm - triggers on an alarm going off\nredstone - triggers on any change to redstone",
  150. "9.3 - What types of events are there\n\ndisk - triggers on disk insertion\ndisk_eject - triggers on disk ejection",
  151. "9.4 - Using event loops\n\nUsing the pullEvent() function inside a loop is a great way to determine when to break the loop. For instance:\n\nwhile true do\nevent, param1, param2 = event.pull()\n if event == \"char\" and param1 == \"q\" then\n break\n end\nend",
  152. "9.5 - WHATS GOING ON!\nThis is a cool test program to make, so that you can see exactly whats happening in events.\n\nwhile true do\nevent, param1, param2, param3 = event.pull()\nprint (\"Event = \"..event)\nprint (param1)\nprint (param2)\nprint (param3)\nend\n\nDon't Forget to Hold control+t to exit the loop.",
  153. "9.6 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  154. "SIM"
  155. },
  156. [10] = {
  157. "Key Points in this Chapter:\n\n1. What is a function?\n2. How to use a basic function\n3. How to get a return value from a function",
  158. "10.1 - What is a function\n\nThink of a function as a part of your code that can be ran from anywhere inside your code. Once your function is done running, it will take you back to where your code left off.",
  159. "10.2 - How to use a basic function\n\nfunction hello()\nprint (\"Hello\")\nend\n\n Here we created a function named hello, and inside that function we placed a print statement that says hello.",
  160. "10.2 - How to use a basic function\n\nNow that we have our function created, anytime and anywhere in our program, we can place\nhello()\nThis will jump to the function, run the functions code, then come back to where you called the function.",
  161. "10.3 - How to get a return value from a function\n\nMost of the time we want our functions to do repetitious tasks for us though, to do this we can create a more advanced function that will return a value based on what happens in the function.",
  162. "10.3 - How to get a return value from a function\n\nfunction add(num1, num2)\nresult = tonumber(num1) + tonumber(num2)\nreturn result\nend\n\nThis is our adding function, it takes 2 numbers that we supply and returns the result.",
  163. "10.3 - How to get a return value from a function\n\nTo call our adding function we use.\nx = add(5,5)\nThis makes the add function use the numbers 5 and 5, which it will then add together and return to us. We save that return data in x",
  164. "10.3 - How to get a return value from a function\n\nBy combining what we already know, we must assume that we can use variables instead of numbers in our function. Therefor making:\nx = add(x, y)\nA perfectly good way to add 2 variables together.",
  165. "10.4 - Practice What We've Learned!\n\nYou'll see a new option at the bottom of your screen now. You can press [SPACE] to continue onward to the next chapter, you can also press [ENTER] to run this chapters simulation.\nDon't worry, you won't hurt my feelings by not practicing.",
  166. "SIM"
  167. },
  168. [11] = {
  169. "This is not a Chapter, this is just random blurbs of extra information about other features and functions.",
  170. "Blurb 0 (The Most Important) - Use NOTEPAD++ to edit your code, the in-game edit kinda sucks\n\nFind your code in saves/world/computer/#",
  171. "Blurb 1 - os.sleep(1) will pause your code for 1 second",
  172. "Blurb 2 - timername = os.startTimer(1) will cause a timer to go off in 1 second, use events to check for the name",
  173. "Blurb 3 - Making your code readable helps everyone\nwhile true do\nif x == 5 then\nend\nend\nCOULD BE\nwhile true do\n if x == 5 then\n end\nend",
  174. "Blurb 4 - Atleast 75% of the time, an error tells you exactly whats wrong with your program.\nSomething with NIL means your trying to use a NIL variable.",
  175. "Blurb 5 - Google Is your friend, just try \"lua strings tutorial\"",
  176. "Blurb 6 - Theres DOZENS of functions I didn't go over, you should read about them on the interwebs\nstring.len()\nstring.sub()\nstring.find()\nio.open()\nio.close()",
  177. "Blurb 7 - No one will help you if you don't work on the code yourself and provide them with it.",
  178. "Blurb 8 - When your ready for more advanced coding, start looking into the default programs as well as other user created content.",
  179. "Blurb 9 - Using matrice's is a good test to see if your grasping lua",
  180. "Blurb 10 - You don't have to use functions if you trully don't understand them, they can make your life easier, but they can also make your life much harder.",
  181. "Blurb 11 - Find help on IRC, but prepare to have code ready to be shown. http://webchat.esper.net/?channels=#oc",
  182. "Blurb 12 - You can do almost anything your imagination can think up.....except magic",
  183. "Blurb 13 - By holding Control+t you can terminate any program. By holding Control+r you can reboot any computer.",
  184. "END"
  185. }
  186. }
  187.  
  188. --"Event Checker""String Functions","File Functions","Math Functions","Calling Another Program","Disk Functions",
  189. Examples = {
  190. [1] = {
  191. "Event Checker",
  192. "This example is a great way to check what event is being passed through the pullEvent() statement. It uses a while loop that continually checks the pull event until the q key is pressed.",
  193. [[
  194. term.clear()
  195. term.setCursor(1,1)
  196. while true do
  197. param1 = getCh()
  198. print (event)
  199. print (param1)
  200. print (param2)
  201. if event == "char" and param1 == "q" then
  202. break
  203. end
  204. end
  205. ]],
  206. "eventchecker" -- filename to be saved as
  207. },
  208. [2] = {
  209. "String Functions",
  210. "This example uses some basic string functions to modify a string, we will take a long string and shorten it to 10 characters which will all be lowercased.",
  211. [[
  212. text = "Hello user and Welcome to the World of OpenComputers"
  213. blah = string.sub(text, 1, 10)
  214. -- This line says that blah is now equal to 1-10 of text.
  215. blah = string.lower(blah)
  216. -- This line says that blah is now equal to an all lowercase blah.
  217. print (blah)
  218. -- This outputs as hello user
  219. ]],
  220. "stringfunc"
  221. },
  222. [3] = {
  223. "File Functions",
  224. "This example will check to see if the file exists we will open it in \"r\" mode to read, it will then read line by line from the file and store that data into an array, we will then print each line of the file with a 1 second sleep between them. We can use the file:write(variable) statement if the file is opened in write mode \"w\". We can append a file with the \"wa\" mode.",
  225. [[
  226. filename = "tutorial"
  227. if fs.exists(filename) == true then
  228. file = io.open(filename, "r")
  229. local i = 1
  230. local line = {}
  231. while true do
  232. line[i] = file:read()
  233. if line[i] == nil then
  234. break
  235. end
  236. print (line[i])
  237. os.sleep (1)
  238. i = i + 1
  239. end
  240. else
  241. print ("File doesn't exist.")
  242. end
  243. ]],
  244. "filefunc"
  245. },
  246. [4] = {
  247. "Math Functions",
  248. "This tutorial will go over some of the math functions, we'll start with a random number from 1-10, we will then divide that by another random number from 1-20. We will take the result and round upwards to a whole number. Meaning that if our answer is 3.1 it will still round up to 4. You'll notice the math.ciel function which does our rounding, we could also use math.floor which would round down instead.",
  249. [[
  250. num1 = math.random(1,10)
  251. num2 = math.random(1,20)
  252. print ("Number 1 is "..num1)
  253. print ("Number 2 is "..num2)
  254. result = num1 / num2
  255. print ("UnRounded Result is "..result)
  256. result = math.ceil(result)
  257. print ("Rounded Up Result is "..result)
  258. ]],
  259. "mathfunc"
  260. },
  261. [5] = {
  262. "Calling Another Program",
  263. "This tutorial is very basic, but is a very powerful function as well. The shell.execute command allows us to run a command from within our program as if we were at the terminal.",
  264. [[
  265. shell.execute("programname")
  266. shell.execute("mkdir", nil, "testing")
  267. This would create a testing directory
  268. shell.execute("copy", "disk/hello", "world")
  269. This would copy the program hello from the disk directory
  270. and place it as a program called world in your root
  271. directory.
  272. ]],
  273. "callprogram"
  274. },
  275. [6] = {
  276. "Disk Functions",
  277. "This tutorial will go over some of the basic floppy functions. We will check to see if a floppy is inserted using the pullEvent() loop, we will then make sure the floppy doesn't have a label, and if it's label is empty we will label it Blank and exit the program. We can learn more about the disk functions by typing help disk at the terminal.",
  278. [[
  279. while true do
  280. local event, param1 = event.pull()
  281. if event == "disk" then
  282. if disk.getLabel(param1) == nil then
  283. disk.setLabel(param1, "Blank")
  284. print ("Disk labeled to Blank")
  285. print ("Disk is in the "..param1.." side")
  286. break
  287. else
  288. print ("Disk already has a label.")
  289. print ("Disk is in the "..param1.." side")
  290. break
  291. end
  292. end
  293. end
  294. ]],
  295. "diskfunc"
  296. }
  297. }
  298.  
  299. function SaveExamples()
  300. term.clear()
  301. term.setCursor(1,1)
  302. print "This will save all of the example programs into the examples folder."
  303. print ""
  304. print "You can access this folder by typing"
  305. print "cd examples"
  306. print "You can list the examples by typing"
  307. print "ls"
  308. print "You can simply edit the file to look"
  309. print "at it, or you can open the file inside"
  310. print "your computer by finding it in your"
  311. print "saves directory under your worldname"
  312. print "and the folder number of your hard drive."
  313. print ""
  314. pressany()
  315. os.sleep(.5)
  316. local path = fs.path(require("process").running())
  317. if fs.exists(path.."/examples") then
  318. print(" ")
  319. else
  320. fs.makeDirectory(path.."/examples")
  321. end
  322.  
  323. local i = 1
  324. while true do
  325. if Examples[i] ~= nil then
  326. if fs.exists(path.."examples/"..Examples[i][4]) then
  327. print("Files already exist. exiting the save function")
  328. os.sleep(3)
  329. return
  330. end
  331. local file = io.open(path.."examples/"..Examples[i][4], "w")
  332. file:write("--[[\n")
  333. file:write(Examples[i][2])
  334. file:write("--]]\n")
  335. file:write(Examples[i][3])
  336. file:close()
  337. i = i + 1
  338. else
  339. break
  340. end
  341. end
  342. term.clear()
  343. term.setCursor(1,1)
  344. print "Examples correctly saved to /examples"
  345. pressany()
  346. end
  347.  
  348. function spaces(cnt)
  349. return string.rep(string.char(32), cnt)
  350. end
  351.  
  352. local function spChar(letter, cnt)
  353. return string.rep(unicode.char(letter), cnt)
  354. end
  355.  
  356. function mainmenu()
  357.  
  358. while true do
  359. term.clear()
  360. term.setCursor(1,1)
  361.  
  362. print (spChar(ul[1], 1)..spChar(al[1],38)..spChar(ur[1], 1))
  363. print (spChar(sl[1], 1).." OpenComputers Interactive Tutorial "..spChar(sl[1], 1))
  364. print (spChar(sl[1], 1).." By: Casper7526 (ported by Kenny) "..spChar(sl[1], 1))
  365. print (spChar(0x251C, 1)..spChar(al[1],38)..spChar(0x2524, 1))
  366. print (spChar(sl[1], 1)..spaces(38)..spChar(sl[1], 1))
  367. print (spChar(sl[1], 1).." 1. Start "..spChar(sl[1], 1))
  368. print (spChar(sl[1], 1).." 2. Choose Chapter "..spChar(sl[1], 1))
  369. print (spChar(sl[1], 1).." 3. Examples "..spChar(sl[1], 1))
  370. print (spChar(sl[1], 1).." 4. Save Examples To File "..spChar(sl[1], 1))
  371. print (spChar(sl[1], 1).." 5. Exit "..spChar(sl[1], 1))
  372. print (spChar(sl[1], 1)..spaces(38)..spChar(sl[1], 1))
  373. print (spChar(ll[1], 1)..spChar(al[1],38)..spChar(lr[1], 1))
  374. local param1 = getCh()
  375. if param1 == keyboard.keys["5"] then
  376. break
  377. elseif param1 == keyboard.keys["1"] then
  378. chapter = 1 LoadChapter(chapter)
  379. elseif param1 == keyboard.keys["2"] then
  380. ChooseChapter()
  381. elseif param1 == keyboard.keys["3"] then
  382. ChooseExample()
  383. elseif param1 == keyboard.keys["4"] then
  384. SaveExamples()
  385. end
  386. end
  387. end
  388.  
  389. function LoadExample(num)
  390. term.clear()
  391. term.setCursor(1,1)
  392. print (Examples[num][2])
  393. pressany()
  394. term.clear()
  395. os.sleep(.5)
  396. term.setCursor(1,1)
  397. print (Examples[num][3])
  398. pressany()
  399. end
  400.  
  401. function ChooseExample()
  402. while true do
  403. term.clear()
  404. term.setCursor(1,1)
  405. print (spChar(ul[1], 1)..spChar(al[1],39)..spChar(ur[1], 1))
  406. print (spChar(sl[1], 1)..spaces(13).."Example Index"..spaces(13)..spChar(sl[1], 1))
  407. print (spChar(0x251C, 1)..spChar(al[1],39)..spChar(0x2524, 1))
  408. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  409. local i = 1
  410. while true do
  411. if Examples[i] == nil then
  412. break
  413. end
  414. print (spChar(sl[1],1).." "..i..". "..text.trim(Examples[i][1])..spaces(34-string.len(text.trim(Examples[i][1])))..spChar(sl[1], 1))
  415. i = i + 1
  416. end
  417. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  418. print (spChar(sl[1], 1).." q. Quit"..spaces(30)..spChar(sl[1], 1))
  419. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  420. print (spChar(ll[1], 1)..spChar(al[1],39)..spChar(lr[1], 1))
  421. term.write "Choice - "
  422. choice = io.read()
  423. if string.lower(choice) == "q" then
  424. break
  425. end
  426. if Examples[tonumber(choice)] == nil then
  427. print "Thats not a valid chapter." os.sleep(1)
  428. else
  429. LoadExample(tonumber(choice))
  430. break
  431. end
  432. end
  433. end
  434.  
  435.  
  436.  
  437. function ChooseChapter()
  438. while true do
  439. term.clear()
  440. term.setCursor(1,1)
  441. print (spChar(ul[1], 1)..spChar(al[1],39)..spChar(ur[1], 1))
  442. print (spChar(sl[1], 1)..spaces(13).."Chapter Index"..spaces(13)..spChar(sl[1], 1))
  443. print (spChar(0x251C, 1)..spChar(al[1],39)..spChar(0x2524, 1))
  444. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  445. local i = 1
  446. while true do
  447. if ChapterTitles[i] == nil then
  448. break
  449. end
  450. if i < 10 then
  451. spStr = 34
  452. else
  453. spStr = 33
  454. end
  455. print (spChar(sl[1],1).." "..i..". "..text.trim(ChapterTitles[i])..spaces(spStr-string.len(text.trim(ChapterTitles[i])))..spChar(sl[1], 1))
  456. i = i + 1
  457. end
  458. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  459. print (spChar(sl[1], 1).." q. Quit"..spaces(30)..spChar(sl[1], 1))
  460. print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  461. print (spChar(ll[1], 1)..spChar(al[1],39)..spChar(lr[1], 1))
  462. term.write "Choice - "
  463. choice = io.read()
  464. if string.lower(choice) == "q" then
  465. break
  466. end
  467. if ChapterTitles[tonumber(choice)] == nil then
  468. print "Thats not a valid chapter." os.sleep(1)
  469. else
  470. LoadChapter(tonumber(choice))
  471. break
  472. end
  473. end
  474. end
  475.  
  476. function LoadChapter(chapter)
  477. while true do
  478. term.clear()
  479. term.setCursor(1,1)
  480. local spStr = 35
  481. if chapter > 10 then
  482. spStr = 34
  483. end
  484. print (spChar(ul[1], 1)..spChar(al[1],50)..spChar(ur[1], 1))
  485. print (spChar(sl[1], 1)..spaces(3).."Chapter "..chapter.." - "..ChapterTitles[chapter]..spaces(spStr-string.len(ChapterTitles[chapter]))..spChar(sl[1], 1))
  486. print (spChar(ll[1], 1)..spChar(al[1],50)..spChar(lr[1], 1))
  487. print (" "..Chapter[chapter][CurrentSection])
  488. print ""
  489. if Chapter[chapter][CurrentSection + 1] == "END" then
  490. print "THATS ALL FOLKS!"
  491. else
  492. print "Press [Space] To Continue"
  493. end
  494. print "[q] - Main Menu [b] - Previous Page."
  495. if Chapter[chapter][CurrentSection + 1] == "SIM" then
  496. print "Press [Enter] To Run Simulation"
  497. end
  498. local param1 = getCh()
  499. if param1 == keyboard.keys.enter and Chapter[chapter][CurrentSection + 1] == "SIM" then
  500. Sim(chapter) EndSim(chapter) chapter = chapter + 1 CurrentSection = 1
  501. elseif param1 == keyboard.keys.q then
  502. CurrentSection = 1
  503. break
  504. elseif param1 == keyboard.keys.b then
  505. CurrentSection = CurrentSection - 1
  506. if CurrentSection == 0 then
  507. CurrentSection = 1
  508. end
  509. elseif param1 == keyboard.keys.space and Chapter[chapter][CurrentSection + 1] ~= "END" then
  510. if Chapter[chapter][CurrentSection + 1] == "SIM" then
  511. chapter = chapter + 1 CurrentSection = 1
  512. else
  513. CurrentSection = CurrentSection + 1
  514. end
  515. end
  516. end
  517. end
  518.  
  519. function EndSim(chapter)
  520. while true do
  521. term.clear()
  522. term.setCursor(1,1)
  523. print "Great work back there!"
  524. print ""
  525. print "Press [ENTER] to move on to the next chapter"
  526. local param1 = getCh()
  527. if param1 == keyboard.keys.enter then
  528. shell.execute("rm", nil, "tmptut")
  529. break
  530. end
  531. end
  532. end
  533.  
  534. function pressany()
  535. term.setCursor(1,17)
  536. print "Press Any Key To Continue"
  537. pause=getCh()
  538. end
  539.  
  540. function Sim(chapter)
  541. stage = 1
  542. while true do
  543. term.clear()
  544. term.setCursor(1,1)
  545. if chapter == 1 then
  546. print "Your Goals:"
  547. print ""
  548. print "* Create a program named hello."
  549. print "* Type anything you wish inside that program."
  550. print "* Save and Exit the program."
  551. print "* Run the program."
  552. print ""
  553. print "quit will exit the sim early."
  554. term.write (">")
  555. input = io.read()
  556. if input == "quit" then
  557. break
  558. end
  559. if stage == 1 then
  560. if input == "edit hello" then
  561. shell.execute("edit", nil, "tmptut")
  562. print "Great Job, now let's run our program!"
  563. os.sleep(2)
  564. stage = 2
  565. else
  566. print "Remember, lua is case sensitive."
  567. print "Try"
  568. print "edit hello"
  569. os.sleep(2)
  570. end
  571. elseif stage == 2 then
  572. if input == "hello" then
  573. break
  574. else
  575. print "Remember, lua is case sensitive."
  576. print "Try"
  577. print "hello"
  578. os.os.sleep(2)
  579. end
  580. end
  581. end
  582. if chapter == 2 then
  583. print "Your Goals:"
  584. print ""
  585. print "* Create a program named hello."
  586. print "* Clear the Screen"
  587. print "* Set the Cursor Pos to 1,1"
  588. print "* Print \"Hello Loser\" on line 1 of the screen."
  589. print "* Print \"Welcome\" on line 2 of the screen."
  590. print "* Clear the 1st line."
  591. print "* Print \"Hello User\" on line 1 of the screen."
  592. print "* Run your program!"
  593. print ""
  594. print "You can type \"example\" at anytime to see the correct syntax."
  595. print "quit will exit the sim early."
  596. print ""
  597. term.write (">")
  598. input = io.read()
  599. if input == "quit" then
  600. break
  601. elseif input == "edit hello" then
  602. shell.execute("edit", nil, "tmptut")
  603. elseif input == "hello" then
  604. shell.execute("tmptut")
  605. pressany()
  606. term.clear()
  607. term.setCursor(1,1)
  608. print "Did your program work as you expected?"
  609. print ""
  610. print "Press [ENTER] to end the simulation."
  611. print "Press Any Other Key to go back and work on your program."
  612. param1 = getCh()
  613. if param1 == keyboard.keys.enter then
  614. break
  615. end
  616. elseif string.lower(input) == "example" then
  617. term.clear()
  618. term.setCursor(1,1)
  619. print ("term.clear()")
  620. print ("term.setCursor(1,1)")
  621. print ("print (\"Hello Loser\")")
  622. print ("print (\"Welcome\")")
  623. print ("term.setCursor(1,1)")
  624. print ("term.clearLine()")
  625. print ("print (\"Hello User\")")
  626. pressany()
  627. end
  628. end
  629. if chapter == 3 then
  630. print "Your Goals:"
  631. print ""
  632. print "--Use the program hello--"
  633. print "* Create the following variables."
  634. print " x = 1"
  635. print " y = \"2\""
  636. print " z = 0"
  637. print " text = \"Output \""
  638. print "* Add x and y together and store that value in z, then print text and z to the user on the same line."
  639. print "* Run your program!"
  640. print ""
  641. print "You can type \"example\" at anytime to see the correct syntax."
  642. print "quit will exit the sim early."
  643. print ""
  644. term.write (">")
  645. input = io.read()
  646. if input == "quit" then
  647. break
  648. elseif input == "edit hello" then
  649. shell.execute("edit", nil, "tmptut")
  650. elseif input == "hello" then
  651. shell.execute("tmptut")
  652. pressany()
  653. term.clear()
  654. term.setCursor(1,1)
  655. print "Did your program work as you expected?"
  656. print ""
  657. print "Press [ENTER] to end the simulation."
  658. print "Press Any Other Key to go back and work on your program."
  659. param1 = getCh()
  660. if param1 == keyboard.keys.enter then
  661. break
  662. end
  663. elseif string.lower(input) == "example" then
  664. term.clear()
  665. term.setCursor(1,1)
  666. print ("term.clear()")
  667. print ("term.setCursor(1,1)")
  668. print ("x = 1")
  669. print ("y = \"2\"")
  670. print ("z = 0")
  671. print ("text = \"Output \"")
  672. print ("y = tonumber(y)")
  673. print ("z = x + y")
  674. print ("print (text..z)")
  675. pressany()
  676. end
  677. end
  678. if chapter == 4 then
  679. print "Your Goals:"
  680. print ""
  681. print "--Use the program hello--"
  682. print "* Ask the user for their name"
  683. print "* Show them the line:"
  684. print " Hello name how are you today?"
  685. print " With name replaced by their input."
  686. print "* Run your program!"
  687. print ""
  688. print "You can type \"example\" at anytime to see the correct syntax."
  689. print "quit will exit the sim early."
  690. print ""
  691. term.write (">")
  692. input = io.read()
  693. if input == "quit" then
  694. break
  695. elseif input == "edit hello" then
  696. shell.execute("edit", nil, "tmptut")
  697. elseif input == "hello" then
  698. shell.execute("tmptut")
  699. pressany()
  700. term.clear()
  701. term.setCursor(1,1)
  702. print "Did your program work as you expected?"
  703. print ""
  704. print "Press [ENTER] to end the simulation."
  705. print "Press Any Other Key to go back and work on your program."
  706. param1 = getCh()
  707. if param1 == keyboard.keys.enter then
  708. break
  709. end
  710. elseif string.lower(input) == "example" then
  711. term.clear()
  712. term.setCursor(1,1)
  713. print ("term.clear()")
  714. print ("term.setCursor(1,1)")
  715. print ("write(\"Whats your name? \")")
  716. print ("name = io.read()")
  717. print ("print (\"Hello \"..name..\" how are you today?\")")
  718. pressany()
  719. end
  720. end
  721. if chapter == 5 then
  722. print "Your Goals:"
  723. print ""
  724. print "--Use the program hello--"
  725. print "* Ask the user for their name"
  726. print "* If their name is Bob or John then welcome them."
  727. print "* If their name isn't Bob or John, then tell them to get lost!"
  728. print "* Run your program!"
  729. print ""
  730. print "You can type \"example\" at anytime to see the correct syntax."
  731. print "quit will exit the sim early."
  732. print ""
  733. term.write (">")
  734. input = io.read()
  735. if input == "quit" then
  736. break
  737. elseif input == "edit hello" then
  738. shell.execute("edit", nil, "tmptut")
  739. elseif input == "hello" then
  740. shell.execute("tmptut")
  741. pressany()
  742. term.clear()
  743. term.setCursor(1,1)
  744. print "Did your program work as you expected?"
  745. print ""
  746. print "Press [ENTER] to end the simulation."
  747. print "Press Any Other Key to go back and work on your program."
  748. param1 = getCh()
  749. if param1 == keyboard.keys.enter then
  750. break
  751. end
  752. elseif string.lower(input) == "example" then
  753. term.clear()
  754. term.setCursor(1,1)
  755. print ("term.clear()")
  756. print ("term.setCursor(1,1)")
  757. print ("write(\"Whats your name? \")")
  758. print ("name = io.read()")
  759. print ("if name == \"Bob\" or name == \"John\" then ")
  760. print ("print (\"Welcome \"..name)")
  761. print ("else")
  762. print ("print (\"Get lost!\")")
  763. print ("end")
  764. pressany()
  765. end
  766. end
  767. if chapter == 6 then
  768. print "Your Goals:"
  769. print ""
  770. print "--Use the program hello--"
  771. print "* Create a loop that continually asks the user for their name."
  772. print "* Only exit that loop if they enter Bob as their name."
  773. print "* Try using the BREAK statement as well as without."
  774. print "* Run your program!"
  775. print ""
  776. print "You can type \"example\" at anytime to see the correct syntax."
  777. print "quit will exit the sim early."
  778. print ""
  779. term.write (">")
  780. input = io.read()
  781. if input == "quit" then
  782. break
  783. elseif input == "edit hello" then
  784. shell.execute("edit", nil, "tmptut")
  785. elseif input == "hello" then
  786. shell.execute("tmptut")
  787. pressany()
  788. term.clear()
  789. term.setCursor(1,1)
  790. print "Did your program work as you expected?"
  791. print ""
  792. print "Press [ENTER] to end the simulation."
  793. print "Press Any Other Key to go back and work on your program."
  794. param1 = getCh()
  795. if param1 == keyboard.keys.enter then
  796. break
  797. end
  798. elseif string.lower(input) == "example" then
  799. term.clear()
  800. term.setCursor(1,1)
  801. print ("term.clear()")
  802. print ("term.setCursor(1,1)")
  803. print ""
  804. print ("while name ~= \"Bob\" do")
  805. print ("write(\"Whats your name? \")")
  806. print ("name = io.read()")
  807. print ("end")
  808. print ""
  809. print ("while true do")
  810. print ("write(\"Whats your name? \")")
  811. print ("name = io.read()")
  812. print (" if name == \"Bob\" then")
  813. print (" break")
  814. print (" end")
  815. print ("end")
  816. pressany()
  817. end
  818. end
  819. if chapter == 7 then
  820. print "Your Goals:"
  821. print ""
  822. print "--Use the program hello--"
  823. print "* Check to see if there is redstone current coming into the back of your computer"
  824. print "* If there is current coming in the back then turn on the current to the front"
  825. print "* If there isn't current coming in the back, then turn off the current to the front"
  826. print "* Tell the user if you turned the current on or off."
  827. print "* Run your program!"
  828. print ""
  829. print "You can type \"example\" at anytime to see the correct syntax."
  830. print "quit will exit the sim early."
  831. print ""
  832. term.write (">")
  833. input = io.read()
  834. if input == "quit" then
  835. break
  836. elseif input == "edit hello" then
  837. shell.execute("edit", nil, "tmptut")
  838. elseif input == "hello" then
  839. shell.execute("tmptut")
  840. pressany()
  841. term.clear()
  842. term.setCursor(1,1)
  843. print "Did your program work as you expected?"
  844. print ""
  845. print "Press [ENTER] to end the simulation."
  846. print "Press Any Other Key to go back and work on your program."
  847. local param1 = getCh()
  848. if param1 == keyboard.keys.enter then
  849. break
  850. end
  851. elseif string.lower(input) == "example" then
  852. term.clear()
  853. term.setCursor(1,1)
  854. print ("term.clear()")
  855. print ("term.setCursor(1,1)")
  856. print ("if redstone.getInput(\"back\") == true then")
  857. print ("redstone.setOutput(\"front\", true)")
  858. print ("print (\"Front is now on.\")")
  859. print ("else")
  860. print ("redstone.setOutput(\"front\", false)")
  861. print ("print (\"Front is now off.\")")
  862. print ("end")
  863. pressany()
  864. end
  865. end
  866. if chapter == 8 then
  867. print "Your Goals:"
  868. print ""
  869. print "--Use the program hello--"
  870. print "--Use the back output of the computer--"
  871. print "* Turn on white"
  872. print "* Turn on blue"
  873. print "* Turn on purple"
  874. print "* Turn off blue"
  875. print "* Turn off all colors"
  876. print "* Check to see if white is coming in the front"
  877. print "* Run your program!"
  878. print ""
  879. print "You can type \"example\" at anytime to see the correct syntax."
  880. print "quit will exit the sim early."
  881. print ""
  882. term.write (">")
  883. input = io.read()
  884. if input == "quit" then
  885. break
  886. elseif input == "edit hello" then
  887. shell.execute("edit", nil, "tmptut")
  888. elseif input == "hello" then
  889. shell.execute("tmptut")
  890. pressany()
  891. term.clear()
  892. term.setCursor(1,1)
  893. print "Did your program work as you expected?"
  894. print ""
  895. print "Press [ENTER] to end the simulation."
  896. print "Press Any Other Key to go back and work on your program."
  897. local param1 = getCh()
  898. if param1 == keyboard.keys.enter then
  899. break
  900. end
  901. elseif string.lower(input) == "example" then
  902. term.clear()
  903. term.setCursor(1,1)
  904. print ("term.clear()")
  905. print ("term.setCursor(1,1)")
  906. print ("out = colors.combine(colors.white, colors.blue, colors.purple)")
  907. print ("rs.setBundledOutput(\"back\", out)")
  908. print ("out = colors.subtract(out, colors.blue)")
  909. print ("rs.setBundledOutput(\"back\", out)")
  910. print ("rs.setBundledOutput(\"back\", 0)")
  911. print ("in = rs.getBundledInput(\"front\")")
  912. print ("if colors.test(in, colors.white) == true then")
  913. print ("print (\"White is on in front\")")
  914. print ("else")
  915. print ("print (\"White is off in front\")")
  916. print ("end")
  917. pressany()
  918. end
  919. end
  920. if chapter == 9 then
  921. print "Your Goals:"
  922. print ""
  923. print "--Use the program hello--"
  924. print "* Create an event loop"
  925. print "* Print the char that was pressed"
  926. print "* Stop the loop when the q key is pressed"
  927. print "* Stop the loop if the redstone event happens"
  928. print "* Run your program!"
  929. print ""
  930. print "You can type \"example\" at anytime to see the correct syntax."
  931. print "quit will exit the sim early."
  932. print ""
  933. term.write (">")
  934. input = io.read()
  935. if input == "quit" then
  936. break
  937. elseif input == "edit hello" then
  938. shell.execute("edit", nil, "tmptut")
  939. elseif input == "hello" then
  940. shell.execute("tmptut")
  941. pressany()
  942. term.clear()
  943. term.setCursor(1,1)
  944. print "Did your program work as you expected?"
  945. print ""
  946. print "Press [ENTER] to end the simulation."
  947. print "Press Any Other Key to go back and work on your program."
  948. local param1 = getCh()
  949. if param1 == keyboard.keys.enter then
  950. break
  951. end
  952. elseif string.lower(input) == "example" then
  953. term.clear()
  954. term.setCursor(1,1)
  955. print ("term.clear()")
  956. print ("term.setCursor(1,1)")
  957. print ("while true do")
  958. print ("event, param1, param2 = event.pull()")
  959. print (" if event == \"redstone\" then")
  960. print (" break")
  961. print (" end")
  962. print (" if event == \"char\" and param1 == \"q\" then")
  963. print (" break")
  964. print (" else")
  965. print (" print (\"You pressed - \"..param1)")
  966. print (" end")
  967. print ("end")
  968. pressany()
  969. end
  970. end
  971. if chapter == 10 then
  972. print "Your Goals:"
  973. print ""
  974. print "--Use the program hello--"
  975. print "* Ask the user for their first name."
  976. print "* Ask the user for their last name."
  977. print "* Combine the 2 strings using a function"
  978. print " return the result into the fullname variable"
  979. print "* Show the user their full name"
  980. print "* Run your program!"
  981. print ""
  982. print "You can type \"example\" at anytime to see the correct syntax."
  983. print "quit will exit the sim early."
  984. print ""
  985. term.write (">")
  986. input = io.read()
  987. if input == "quit" then
  988. break
  989. elseif input == "edit hello" then
  990. shell.execute("edit", nil, "tmptut")
  991. elseif input == "hello" then
  992. shell.execute("tmptut")
  993. pressany()
  994. term.clear()
  995. term.setCursor(1,1)
  996. print "Did your program work as you expected?"
  997. print ""
  998. print "Press [ENTER] to end the simulation."
  999. print "Press Any Other Key to go back and work on your program."
  1000. local param1 = getCh()
  1001. if param1 == keyboard.keys.enter then
  1002. break
  1003. end
  1004. elseif string.lower(input) == "example" then
  1005. term.clear()
  1006. term.setCursor(1,1)
  1007. print ("term.clear()")
  1008. print ("term.setCursor(1,1)")
  1009. print ("function combine(s1, s2)")
  1010. print ("result = s1..s2")
  1011. print ("return result")
  1012. print ("end")
  1013. print ("write(\"What's your first name? \")")
  1014. print ("firstname = io.read()")
  1015. print ("write(\"What's your last name? \")")
  1016. print ("lastname = io.read()")
  1017. print ("fullname = combine(firstname, lastname)")
  1018. print ("print (\"Hello \"..fullname)")
  1019. pressany()
  1020. end
  1021. end
  1022. end
  1023. end
  1024.  
  1025. mainmenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement