Advertisement
Guest User

OpenComputers in game Lua Tutorial

a guest
Feb 22nd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 54.20 KB | None | 0 0
  1.  
  2. Skip to content
  3.  
  4.     Pull requests
  5.     Issues
  6.     Marketplace
  7.     Explore
  8.  
  9.     @ChelloRae
  10.  
  11. 9
  12. 19
  13.  
  14.     39
  15.  
  16. OpenPrograms/Kenny-Programs
  17. Code
  18. Issues 1
  19. Pull requests 1
  20. Projects 0
  21. Wiki
  22. Insights
  23. Kenny-Programs/Ingame_Lua_Tutorial/LuaTutorial.lua
  24. 4d213bc on Apr 29, 2014
  25. @BigRenegade BigRenegade updated. should be finished, barring any bugs
  26. 1026 lines (1001 sloc) 52.6 KB
  27. local component = require("component")
  28. local fs = require("filesystem")
  29. local internet = require("internet")
  30. local process = require("process")
  31. local event = require("event")
  32. local keyboard = require("keyboard")
  33. local shell = require("shell")
  34. local term = require("term")
  35. local text = require("text")
  36. local unicode = require("unicode")
  37. local sides = require("sides")
  38. local colors=require("colors")
  39.  
  40.  
  41. local ul = {0x250C, 0x2554}
  42. local ur = {0x2510, 0x2557}
  43. local ll = {0x2514, 0x255A}
  44. local lr = {0x2518, 0x255D}
  45. local sl = {0x2502, 0x2551}
  46. local al = {0x2500, 0x2550}
  47.  
  48. function getCh()
  49.     return (select(4, event.pull("key_down")))
  50. end
  51.  
  52.  
  53. -- BaseLine Variables
  54. CurrentChapter = 1
  55. CurrentSection = 1
  56. ChapterTitles = {
  57.   "How to Create a Program",
  58.   "How to Display and clear Text",
  59.   "How to Use and Display Variables",
  60.   "How to get User Input",
  61.   "How to use IF statements",
  62.   "How to use loops",
  63.   "How to use redstone",
  64.   "How to use redpower bundles",
  65.   "How to use events",
  66.   "How to use functions",
  67.   "Extra Tips and Extra Functions"
  68.   }
  69.  
  70. Chapter = {
  71.   [1] = {
  72.     "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.",
  73.     "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.",
  74.     "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.",
  75.     "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\".",
  76.     "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.",
  77.     "SIM"
  78.     },
  79.   [2] = {
  80.     "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.",
  81.     "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.",
  82.     "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.",
  83.     "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.",
  84.     "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.",
  85.     "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.",
  86.     "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.",
  87.     "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.",
  88.     "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.",
  89.     "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.",
  90.     "SIM"
  91.     },
  92.   [3] = {
  93.     "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",
  94.     "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.",
  95.     "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.",
  96.     "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.",
  97.     "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.",
  98.     "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.",
  99.     "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.",
  100.     "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.",
  101.     "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 ;)",
  102.     "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?",
  103.     "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\"",
  104.     "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.",
  105.     "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)",
  106.     "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.",
  107.     "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\"",
  108.     "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).",
  109.     "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.",
  110.     "SIM"  
  111.     },
  112.   [4] = {
  113.     "Key Points in this Chapter:\n\n1. How to get user input",
  114.     "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.",
  115.     "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",
  116.     "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)",
  117.     "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.",
  118.     "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.",
  119.     "SIM"  
  120.     },
  121.   [5] = {
  122.     "Key Points in this Chapter:\n\n1. What is an IF statement\n2. The ELSE statement\n3. The ELSEIF statement\n4. Complex IF's",
  123.     "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.",
  124.     "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.",
  125.     "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.",
  126.     "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",
  127.     "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.",
  128.     "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.",
  129.     "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",
  130.     "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.",
  131.     "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",
  132.     "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.",
  133.     "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",
  134.     "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.",
  135.     "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.",
  136.     "SIM"  
  137.     },
  138.   [6] = {
  139.     "Key Points in this Chapter:\n\n1.What is a loop\n2.How to exit a loop\n3.Different kinds of loops",
  140.     "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.",
  141.     "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.",
  142.     "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.",
  143.     "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.",
  144.     "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.",
  145.     "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.",
  146.     "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.",
  147.     "SIM"  
  148.     },
  149.   [7] = {
  150.     "Key Points in this Chapter:\n\n1. Turning on and off redstone\n2. Checking and Setting Redstone",
  151.     "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",
  152.     "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\"",
  153.     "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.",
  154.     "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.",
  155.     "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.",
  156.     "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.",
  157.     "SIM"  
  158.     }, 
  159.   [8] = {
  160.     "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.",
  161.     "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.",
  162.     "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.",
  163.     "8.3 - Using Multiple colors\nUsing multiple colors is much easier when you use the colors.combine colors.subtract functions.",
  164.     "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.",
  165.     "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.",
  166.     "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.",
  167.     "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.",
  168.     "SIM"  
  169.     },
  170.   [9] = {
  171.     "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!",
  172.     "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!",
  173.     "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",
  174.     "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.",
  175.     "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",
  176.     "9.3 - What types of events are there\n\ndisk - triggers on disk insertion\ndisk_eject - triggers on disk ejection",
  177.     "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",
  178.     "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.",
  179.     "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.",
  180.     "SIM"
  181.     },
  182.   [10] = {
  183.     "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",
  184.     "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.",
  185.     "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.",
  186.     "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.",
  187.     "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.",
  188.     "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.",
  189.     "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",
  190.     "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.",
  191.     "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.",
  192.     "SIM"  
  193.     },
  194.   [11] = {
  195.     "This is not a Chapter, this is just random blurbs of extra information about other features and functions.",
  196.     "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/#",
  197.     "Blurb 1 - os.sleep(1) will pause your code for 1 second",
  198.     "Blurb 2 - timername = os.startTimer(1) will cause a timer to go off in 1 second, use events to check for the name",
  199.     "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",
  200.     "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.",
  201.     "Blurb 5 - Google Is your friend, just try \"lua strings tutorial\"",
  202.     "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()",
  203.     "Blurb 7 - No one will help you if you don't work on the code yourself and provide them with it.",
  204.     "Blurb 8 - When your ready for more advanced coding, start looking into the default programs as well as other user created content.",
  205.     "Blurb 9 - Using matrice's is a good test to see if your grasping lua",
  206.     "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.",
  207.     "Blurb 11 - Find help on IRC, but prepare to have code ready to be shown. http://webchat.esper.net/?channels=#oc",
  208.     "Blurb 12 - You can do almost anything your imagination can think up.....except magic",
  209.     "Blurb 13 - By holding Control+t you can terminate any program. By holding Control+r you can reboot any computer.",
  210.     "END"
  211.    }
  212.   }
  213.  
  214. --"Event Checker""String Functions","File Functions","Math Functions","Calling Another Program","Disk Functions",
  215. Examples = {
  216.   [1] = {
  217.     "Event Checker",
  218.     "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.",
  219.     [[
  220.     term.clear()
  221.     term.setCursor(1,1)
  222.     while true do
  223.       param1 = getCh()
  224.       print (event)
  225.       print (param1)
  226.       print (param2)
  227.       if event == "char" and param1 == "q" then
  228.         break
  229.       end
  230.     end
  231.     ]],
  232.     "eventchecker" -- filename to be saved as
  233.     },
  234.   [2] = {
  235.     "String Functions",
  236.     "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.",
  237.     [[
  238.     text = "Hello user and Welcome to the World of OpenComputers"
  239.     blah = string.sub(text, 1, 10)
  240.     -- This line says that blah is now equal to 1-10 of text.
  241.     blah = string.lower(blah)
  242.     -- This line says that blah is now equal to an all lowercase blah.
  243.     print (blah)
  244.     -- This outputs as hello user
  245.     ]],
  246.     "stringfunc"
  247.     },
  248.   [3] = {
  249.     "File Functions",
  250.     "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.",
  251.     [[
  252.     filename = "tutorial"
  253.     if fs.exists(filename) == true then
  254.       file = io.open(filename, "r")
  255.       local i = 1
  256.       local line = {}
  257.       while true do
  258.         line[i] = file:read()
  259.         if line[i] == nil then
  260.           break
  261.         end
  262.         print (line[i])
  263.         os.sleep (1)
  264.         i = i + 1
  265.       end
  266.     else
  267.       print ("File doesn't exist.")
  268.     end
  269.     ]],
  270.     "filefunc"
  271.     },
  272.   [4] = {
  273.     "Math Functions",
  274.     "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.",
  275.     [[
  276.     num1 = math.random(1,10)
  277.     num2 = math.random(1,20)
  278.     print ("Number 1 is "..num1)
  279.     print ("Number 2 is "..num2)
  280.     result = num1 / num2
  281.     print ("UnRounded Result is "..result)
  282.     result = math.ceil(result)
  283.     print ("Rounded Up Result is "..result)
  284.     ]],
  285.     "mathfunc"
  286.     },
  287.   [5] = {
  288.     "Calling Another Program",
  289.     "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.",
  290.     [[
  291.     shell.execute("programname")
  292.     shell.execute("mkdir", nil, "testing")
  293.     This would create a testing directory
  294.     shell.execute("copy", "disk/hello", "world")
  295.     This would copy the program hello from the disk directory
  296.     and place it as a program called world in your root
  297.     directory.
  298.     ]],
  299.     "callprogram"
  300.     },
  301.   [6] = {
  302.     "Disk Functions",
  303.     "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.",
  304.     [[
  305.     while true do
  306.       local event, param1 = event.pull()
  307.       if event == "disk" then
  308.         if disk.getLabel(param1) == nil then
  309.           disk.setLabel(param1, "Blank")
  310.           print ("Disk labeled to Blank")
  311.           print ("Disk is in the "..param1.." side")
  312.           break
  313.         else
  314.           print ("Disk already has a label.")
  315.           print ("Disk is in the "..param1.." side")
  316.           break
  317.         end
  318.       end
  319.     end
  320.     ]],
  321.     "diskfunc"
  322.     }
  323.   }
  324.  
  325. function SaveExamples()
  326.   term.clear()
  327.   term.setCursor(1,1)
  328.   print "This will save all of the example programs into the examples folder."
  329.   print ""
  330.   print "You can access this folder by typing"
  331.   print "cd examples"
  332.   print "You can list the examples by typing"
  333.   print "ls"
  334.   print "You can simply edit the file to look"
  335.   print "at it, or you can open the file inside"
  336.   print "your computer by finding it in your"
  337.   print "saves directory under your worldname"
  338.   print "and the folder number of your hard drive."
  339.   print ""
  340.   pressany()
  341.   os.sleep(.5)
  342.   local path = fs.path(require("process").running())
  343.   if fs.exists(path.."/examples") then
  344.     print(" ")
  345.   else
  346.     fs.makeDirectory(path.."/examples")
  347.   end
  348.  
  349.   local i = 1
  350.   while true do
  351.     if Examples[i] ~= nil then
  352.       if fs.exists(path.."examples/"..Examples[i][4]) then
  353.         print("Files already exist. exiting the save function")
  354.         os.sleep(3)
  355.         return
  356.       end
  357.       local file = io.open(path.."examples/"..Examples[i][4], "w")
  358.       file:write("--[[\n")
  359.       file:write(Examples[i][2])
  360.       file:write("--]]\n")
  361.       file:write(Examples[i][3])
  362.       file:close()
  363.       i = i + 1
  364.     else
  365.       break
  366.     end
  367.   end
  368.   term.clear()
  369.   term.setCursor(1,1)
  370.   print "Examples correctly saved to /examples"
  371.   pressany()
  372. end
  373.  
  374. function spaces(cnt)
  375.     return string.rep(string.char(32), cnt)
  376. end
  377.  
  378. local function spChar(letter, cnt)
  379.     return string.rep(unicode.char(letter), cnt)
  380. end
  381.  
  382. function mainmenu()
  383.  
  384.   while true do
  385.     term.clear()
  386.     term.setCursor(1,1)
  387.    
  388.     print (spChar(ul[1], 1)..spChar(al[1],38)..spChar(ur[1], 1))
  389.     print (spChar(sl[1], 1).."  OpenComputers Interactive Tutorial  "..spChar(sl[1], 1))
  390.     print (spChar(sl[1], 1).."   By: Casper7526 (ported by Kenny)   "..spChar(sl[1], 1))
  391.     print (spChar(0x251C, 1)..spChar(al[1],38)..spChar(0x2524, 1))
  392.     print (spChar(sl[1], 1)..spaces(38)..spChar(sl[1], 1))
  393.     print (spChar(sl[1], 1).."  1. Start                            "..spChar(sl[1], 1))
  394.     print (spChar(sl[1], 1).."  2. Choose Chapter                   "..spChar(sl[1], 1))
  395.     print (spChar(sl[1], 1).."  3. Examples                         "..spChar(sl[1], 1))
  396.     print (spChar(sl[1], 1).."  4. Save Examples To File            "..spChar(sl[1], 1))
  397.     print (spChar(sl[1], 1).."  5. Exit                             "..spChar(sl[1], 1))
  398.     print (spChar(sl[1], 1)..spaces(38)..spChar(sl[1], 1))
  399.     print (spChar(ll[1], 1)..spChar(al[1],38)..spChar(lr[1], 1))
  400.     local param1 = getCh()
  401.     if param1 == keyboard.keys["5"] then
  402.       break
  403.     elseif param1 == keyboard.keys["1"] then
  404.       chapter = 1 LoadChapter(chapter)
  405.     elseif param1 == keyboard.keys["2"] then
  406.       ChooseChapter()
  407.     elseif param1 == keyboard.keys["3"] then
  408.       ChooseExample()
  409.     elseif param1 == keyboard.keys["4"] then
  410.       SaveExamples()
  411.     end
  412.   end
  413. end
  414.  
  415. function LoadExample(num)
  416.   term.clear()
  417.   term.setCursor(1,1)
  418.   print (Examples[num][2])
  419.   pressany()
  420.   term.clear()
  421.   os.sleep(.5)
  422.   term.setCursor(1,1)
  423.   print (Examples[num][3])
  424.   pressany()
  425. end
  426.  
  427. function ChooseExample()
  428.   while true do
  429.     term.clear()
  430.     term.setCursor(1,1)
  431.     print (spChar(ul[1], 1)..spChar(al[1],39)..spChar(ur[1], 1))
  432.     print (spChar(sl[1], 1)..spaces(13).."Example Index"..spaces(13)..spChar(sl[1], 1))
  433.     print (spChar(0x251C, 1)..spChar(al[1],39)..spChar(0x2524, 1))
  434.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  435.     local i = 1
  436.     while true do
  437.       if Examples[i] == nil then
  438.         break
  439.       end
  440.       print (spChar(sl[1],1).."  "..i..". "..text.trim(Examples[i][1])..spaces(34-string.len(text.trim(Examples[i][1])))..spChar(sl[1], 1))
  441.       i = i + 1
  442.     end
  443.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  444.     print (spChar(sl[1], 1).."  q. Quit"..spaces(30)..spChar(sl[1], 1))
  445.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  446.     print (spChar(ll[1], 1)..spChar(al[1],39)..spChar(lr[1], 1))
  447.     term.write "Choice - "
  448.     choice = io.read()
  449.     if string.lower(choice) == "q" then
  450.       break
  451.     end
  452.     if Examples[tonumber(choice)] == nil then
  453.       print "Thats not a valid chapter." os.sleep(1)
  454.     else
  455.       LoadExample(tonumber(choice))
  456.       break
  457.     end
  458.   end
  459. end
  460.  
  461.  
  462.  
  463. function ChooseChapter()
  464.   while true do
  465.     term.clear()
  466.     term.setCursor(1,1)
  467.     print (spChar(ul[1], 1)..spChar(al[1],39)..spChar(ur[1], 1))
  468.     print (spChar(sl[1], 1)..spaces(13).."Chapter Index"..spaces(13)..spChar(sl[1], 1))
  469.     print (spChar(0x251C, 1)..spChar(al[1],39)..spChar(0x2524, 1))
  470.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  471.     local i = 1
  472.     while true do
  473.       if ChapterTitles[i] == nil then
  474.         break
  475.       end
  476.       if i < 10 then
  477.         spStr = 34
  478.       else
  479.         spStr = 33
  480.       end
  481.       print (spChar(sl[1],1).."  "..i..". "..text.trim(ChapterTitles[i])..spaces(spStr-string.len(text.trim(ChapterTitles[i])))..spChar(sl[1], 1))
  482.       i = i + 1
  483.     end
  484.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  485.     print (spChar(sl[1], 1).."  q. Quit"..spaces(30)..spChar(sl[1], 1))
  486.     print (spChar(sl[1], 1)..spaces(39)..spChar(sl[1], 1))
  487.     print (spChar(ll[1], 1)..spChar(al[1],39)..spChar(lr[1], 1))
  488.     term.write "Choice - "
  489.     choice = io.read()
  490.     if string.lower(choice) == "q" then
  491.       break
  492.     end
  493.     if ChapterTitles[tonumber(choice)] == nil then
  494.       print "Thats not a valid chapter." os.sleep(1)
  495.     else
  496.       LoadChapter(tonumber(choice))
  497.       break
  498.     end
  499.   end
  500. end
  501.  
  502. function LoadChapter(chapter)
  503.   while true do
  504.     term.clear()
  505.     term.setCursor(1,1)
  506.     local spStr = 35
  507.     if chapter > 10 then
  508.       spStr = 34
  509.     end
  510.     print (spChar(ul[1], 1)..spChar(al[1],50)..spChar(ur[1], 1))
  511.     print (spChar(sl[1], 1)..spaces(3).."Chapter "..chapter.." - "..ChapterTitles[chapter]..spaces(spStr-string.len(ChapterTitles[chapter]))..spChar(sl[1], 1))
  512.     print (spChar(ll[1], 1)..spChar(al[1],50)..spChar(lr[1], 1))
  513.     print ("   "..Chapter[chapter][CurrentSection])
  514.     print ""
  515.     if Chapter[chapter][CurrentSection + 1] == "END" then
  516.       print "THATS ALL FOLKS!"
  517.     else
  518.       print "Press [Space] To Continue"
  519.     end
  520.     print "[q] - Main Menu [b] - Previous Page."
  521.     if Chapter[chapter][CurrentSection + 1] == "SIM" then
  522.       print "Press [Enter] To Run Simulation"
  523.     end
  524.     local param1 = getCh()
  525.     if param1 == keyboard.keys.enter and Chapter[chapter][CurrentSection + 1] == "SIM" then
  526.       Sim(chapter) EndSim(chapter) chapter = chapter + 1 CurrentSection = 1
  527.     elseif param1 == keyboard.keys.q then
  528.       CurrentSection = 1
  529.       break
  530.     elseif param1 == keyboard.keys.b then
  531.       CurrentSection = CurrentSection - 1
  532.       if CurrentSection == 0 then
  533.         CurrentSection = 1
  534.       end
  535.     elseif param1 == keyboard.keys.space and Chapter[chapter][CurrentSection + 1] ~= "END" then
  536.       if Chapter[chapter][CurrentSection + 1] == "SIM" then
  537.         chapter = chapter + 1 CurrentSection = 1
  538.       else
  539.         CurrentSection = CurrentSection + 1
  540.       end
  541.     end
  542.   end
  543. end
  544.  
  545. function EndSim(chapter)
  546.   while true do
  547.     term.clear()
  548.     term.setCursor(1,1)
  549.     print "Great work back there!"
  550.     print ""
  551.     print "Press [ENTER] to move on to the next chapter"
  552.     local param1 = getCh()
  553.     if param1 == keyboard.keys.enter then
  554.       shell.execute("rm", nil, "tmptut")
  555.       break
  556.     end
  557.   end
  558. end
  559.  
  560. function pressany()
  561.   term.setCursor(1,17)
  562.   print "Press Any Key To Continue"
  563.   pause=getCh()
  564. end
  565.  
  566. function Sim(chapter)
  567.   stage = 1
  568.   while true do
  569.     term.clear()
  570.     term.setCursor(1,1)
  571.     if chapter == 1 then
  572.       print "Your Goals:"
  573.       print ""
  574.       print "* Create a program named hello."
  575.       print "* Type anything you wish inside that program."
  576.       print "* Save and Exit the program."
  577.       print "* Run the program."
  578.       print ""
  579.       print "quit will exit the sim early."
  580.       term.write (">")
  581.       input = io.read()
  582.       if input == "quit" then
  583.         break
  584.       end
  585.       if stage == 1 then
  586.         if input == "edit hello" then
  587.           shell.execute("edit", nil, "tmptut")
  588.           print "Great Job, now let's run our program!"
  589.           os.sleep(2)
  590.           stage = 2
  591.         else
  592.           print "Remember, lua is case sensitive."
  593.           print "Try"
  594.           print "edit hello"
  595.           os.sleep(2)  
  596.         end
  597.       elseif stage == 2 then
  598.         if input == "hello" then
  599.           break
  600.         else
  601.           print "Remember, lua is case sensitive."
  602.           print "Try"
  603.           print "hello"
  604.           os.os.sleep(2)   
  605.         end
  606.       end
  607.     end
  608.     if chapter == 2 then
  609.       print "Your Goals:"
  610.       print ""
  611.       print "* Create a program named hello."
  612.       print "* Clear the Screen"
  613.       print "* Set the Cursor Pos to 1,1"
  614.       print "* Print \"Hello Loser\" on line 1 of the screen."
  615.       print "* Print \"Welcome\" on line 2 of the screen."
  616.       print "* Clear the 1st line."
  617.       print "* Print \"Hello User\" on line 1 of the screen."
  618.       print "* Run your program!"
  619.       print ""
  620.       print "You can type \"example\" at anytime to see the correct syntax."
  621.       print "quit will exit the sim early."
  622.       print ""
  623.       term.write (">")
  624.       input = io.read()
  625.       if input == "quit" then
  626.         break
  627.       elseif input == "edit hello" then
  628.         shell.execute("edit", nil, "tmptut")
  629.       elseif input == "hello" then
  630.         shell.execute("tmptut")
  631.         pressany()
  632.         term.clear()
  633.         term.setCursor(1,1)
  634.         print "Did your program work as you expected?"
  635.         print ""
  636.         print "Press [ENTER] to end the simulation."
  637.         print "Press Any Other Key to go back and work on your program."
  638.         param1 = getCh()
  639.         if param1 == keyboard.keys.enter then
  640.           break
  641.         end
  642.       elseif string.lower(input) == "example" then
  643.         term.clear()
  644.         term.setCursor(1,1)
  645.         print ("term.clear()")
  646.         print ("term.setCursor(1,1)")
  647.         print ("print (\"Hello Loser\")")
  648.         print ("print (\"Welcome\")")
  649.         print ("term.setCursor(1,1)")
  650.         print ("term.clearLine()")
  651.         print ("print (\"Hello User\")")
  652.         pressany()
  653.       end
  654.     end
  655.     if chapter == 3 then
  656.       print "Your Goals:"
  657.       print ""
  658.       print "--Use the program hello--"
  659.       print "* Create the following variables."
  660.       print " x = 1"
  661.       print " y = \"2\""
  662.       print " z = 0"
  663.       print " text = \"Output \""
  664.       print "* Add x and y together and store that value in z, then print text and z to the user on the same line."
  665.       print "* Run your program!"
  666.       print ""
  667.       print "You can type \"example\" at anytime to see the correct syntax."
  668.       print "quit will exit the sim early."
  669.       print ""
  670.       term.write (">")
  671.       input = io.read()
  672.       if input == "quit" then
  673.         break
  674.       elseif input == "edit hello" then
  675.         shell.execute("edit", nil, "tmptut")
  676.       elseif input == "hello" then
  677.         shell.execute("tmptut")
  678.         pressany()
  679.         term.clear()
  680.         term.setCursor(1,1)
  681.         print "Did your program work as you expected?"
  682.         print ""
  683.         print "Press [ENTER] to end the simulation."
  684.         print "Press Any Other Key to go back and work on your program."
  685.         param1 = getCh()
  686.         if param1 == keyboard.keys.enter then
  687.           break
  688.         end
  689.       elseif string.lower(input) == "example" then
  690.         term.clear()
  691.         term.setCursor(1,1)
  692.         print ("term.clear()")
  693.         print ("term.setCursor(1,1)")
  694.         print ("x = 1")
  695.         print ("y = \"2\"")
  696.         print ("z = 0")
  697.         print ("text = \"Output \"")
  698.         print ("y = tonumber(y)")
  699.         print ("z = x + y")
  700.         print ("print (text..z)")
  701.         pressany()
  702.       end
  703.     end
  704.     if chapter == 4 then
  705.       print "Your Goals:"
  706.       print ""
  707.       print "--Use the program hello--"
  708.       print "* Ask the user for their name"
  709.       print "* Show them the line:"
  710.       print " Hello name how are you today?"
  711.       print " With name replaced by their input."
  712.       print "* Run your program!"
  713.       print ""
  714.       print "You can type \"example\" at anytime to see the correct syntax."
  715.       print "quit will exit the sim early."
  716.       print ""
  717.       term.write (">")
  718.       input = io.read()
  719.       if input == "quit" then
  720.         break
  721.       elseif input == "edit hello" then
  722.         shell.execute("edit", nil, "tmptut")
  723.       elseif input == "hello" then
  724.         shell.execute("tmptut")
  725.         pressany()
  726.         term.clear()
  727.         term.setCursor(1,1)
  728.         print "Did your program work as you expected?"
  729.         print ""
  730.         print "Press [ENTER] to end the simulation."
  731.         print "Press Any Other Key to go back and work on your program."
  732.         param1 = getCh()
  733.         if param1 == keyboard.keys.enter then
  734.           break
  735.         end
  736.       elseif string.lower(input) == "example" then
  737.         term.clear()
  738.         term.setCursor(1,1)
  739.         print ("term.clear()")
  740.         print ("term.setCursor(1,1)")
  741.         print ("write(\"Whats your name? \")")
  742.         print ("name = io.read()")
  743.         print ("print (\"Hello \"..name..\" how are you today?\")")
  744.         pressany()
  745.       end
  746.     end
  747.     if chapter == 5 then
  748.       print "Your Goals:"
  749.       print ""
  750.       print "--Use the program hello--"
  751.       print "* Ask the user for their name"
  752.       print "* If their name is Bob or John then welcome them."
  753.       print "* If their name isn't Bob or John, then tell them to get lost!"
  754.       print "* Run your program!"
  755.       print ""
  756.       print "You can type \"example\" at anytime to see the correct syntax."
  757.       print "quit will exit the sim early."
  758.       print ""
  759.       term.write (">")
  760.       input = io.read()
  761.       if input == "quit" then
  762.         break
  763.       elseif input == "edit hello" then
  764.         shell.execute("edit", nil, "tmptut")
  765.       elseif input == "hello" then
  766.         shell.execute("tmptut")
  767.         pressany()
  768.         term.clear()
  769.         term.setCursor(1,1)
  770.         print "Did your program work as you expected?"
  771.         print ""
  772.         print "Press [ENTER] to end the simulation."
  773.         print "Press Any Other Key to go back and work on your program."
  774.         param1 = getCh()
  775.         if param1 == keyboard.keys.enter then
  776.           break
  777.         end
  778.       elseif string.lower(input) == "example" then
  779.         term.clear()
  780.         term.setCursor(1,1)
  781.         print ("term.clear()")
  782.         print ("term.setCursor(1,1)")
  783.         print ("write(\"Whats your name? \")")
  784.         print ("name = io.read()")
  785.         print ("if name == \"Bob\" or name == \"John\" then ")
  786.         print ("print (\"Welcome \"..name)")
  787.         print ("else")
  788.         print ("print (\"Get lost!\")")
  789.         print ("end")
  790.         pressany()
  791.       end
  792.     end
  793.     if chapter == 6 then
  794.       print "Your Goals:"
  795.       print ""
  796.       print "--Use the program hello--"
  797.       print "* Create a loop that continually asks the user for their name."
  798.       print "* Only exit that loop if they enter Bob as their name."
  799.       print "* Try using the BREAK statement as well as without."
  800.       print "* Run your program!"
  801.       print ""
  802.       print "You can type \"example\" at anytime to see the correct syntax."
  803.       print "quit will exit the sim early."
  804.       print ""
  805.       term.write (">")
  806.       input = io.read()
  807.       if input == "quit" then
  808.         break
  809.       elseif input == "edit hello" then
  810.         shell.execute("edit", nil, "tmptut")
  811.       elseif input == "hello" then
  812.         shell.execute("tmptut")
  813.         pressany()
  814.         term.clear()
  815.         term.setCursor(1,1)
  816.         print "Did your program work as you expected?"
  817.         print ""
  818.         print "Press [ENTER] to end the simulation."
  819.         print "Press Any Other Key to go back and work on your program."
  820.         param1 = getCh()
  821.         if param1 == keyboard.keys.enter then
  822.           break
  823.         end
  824.       elseif string.lower(input) == "example" then
  825.         term.clear()
  826.         term.setCursor(1,1)
  827.         print ("term.clear()")
  828.         print ("term.setCursor(1,1)")
  829.         print ""
  830.         print ("while name ~= \"Bob\" do")
  831.         print ("write(\"Whats your name? \")")
  832.         print ("name = io.read()")
  833.         print ("end")
  834.         print ""
  835.         print ("while true do")
  836.         print ("write(\"Whats your name? \")")
  837.         print ("name = io.read()")
  838.         print (" if name == \"Bob\" then")
  839.         print (" break")
  840.         print (" end")
  841.         print ("end")
  842.         pressany()
  843.       end
  844.     end
  845.     if chapter == 7 then
  846.       print "Your Goals:"
  847.       print ""
  848.       print "--Use the program hello--"
  849.       print "* Check to see if there is redstone current coming into the back of your computer"
  850.       print "* If there is current coming in the back then turn on the current to the front"
  851.       print "* If there isn't current coming in the back, then turn off the current to the front"
  852.       print "* Tell the user if you turned the current on or off."
  853.       print "* Run your program!"
  854.       print ""
  855.       print "You can type \"example\" at anytime to see the correct syntax."
  856.       print "quit will exit the sim early."
  857.       print ""
  858.       term.write (">")
  859.       input = io.read()
  860.       if input == "quit" then
  861.         break
  862.       elseif input == "edit hello" then
  863.         shell.execute("edit", nil, "tmptut")
  864.       elseif input == "hello" then
  865.         shell.execute("tmptut")
  866.         pressany()
  867.         term.clear()
  868.         term.setCursor(1,1)
  869.         print "Did your program work as you expected?"
  870.         print ""
  871.         print "Press [ENTER] to end the simulation."
  872.         print "Press Any Other Key to go back and work on your program."
  873.         local param1 = getCh()
  874.         if param1 == keyboard.keys.enter then
  875.           break
  876.         end
  877.       elseif string.lower(input) == "example" then
  878.         term.clear()
  879.         term.setCursor(1,1)
  880.         print ("term.clear()")
  881.         print ("term.setCursor(1,1)")
  882.         print ("if redstone.getInput(\"back\") == true then")
  883.         print ("redstone.setOutput(\"front\", true)")
  884.         print ("print (\"Front is now on.\")")
  885.         print ("else")
  886.         print ("redstone.setOutput(\"front\", false)")
  887.         print ("print (\"Front is now off.\")")
  888.         print ("end")
  889.         pressany()
  890.       end
  891.     end
  892.     if chapter == 8 then
  893.       print "Your Goals:"
  894.       print ""
  895.       print "--Use the program hello--"
  896.       print "--Use the back output of the computer--"
  897.       print "* Turn on white"
  898.       print "* Turn on blue"
  899.       print "* Turn on purple"
  900.       print "* Turn off blue"
  901.       print "* Turn off all colors"
  902.       print "* Check to see if white is coming in the front"
  903.       print "* Run your program!"
  904.       print ""
  905.       print "You can type \"example\" at anytime to see the correct syntax."
  906.       print "quit will exit the sim early."
  907.       print ""
  908.       term.write (">")
  909.       input = io.read()
  910.       if input == "quit" then
  911.         break
  912.       elseif input == "edit hello" then
  913.         shell.execute("edit", nil, "tmptut")
  914.       elseif input == "hello" then
  915.         shell.execute("tmptut")
  916.         pressany()
  917.         term.clear()
  918.         term.setCursor(1,1)
  919.         print "Did your program work as you expected?"
  920.         print ""
  921.         print "Press [ENTER] to end the simulation."
  922.         print "Press Any Other Key to go back and work on your program."
  923.         local param1 = getCh()
  924.         if param1 == keyboard.keys.enter then
  925.           break
  926.         end
  927.       elseif string.lower(input) == "example" then
  928.         term.clear()
  929.         term.setCursor(1,1)
  930.         print ("term.clear()")
  931.         print ("term.setCursor(1,1)")
  932.         print ("out = colors.combine(colors.white, colors.blue, colors.purple)")
  933.         print ("rs.setBundledOutput(\"back\", out)")
  934.         print ("out = colors.subtract(out, colors.blue)")
  935.         print ("rs.setBundledOutput(\"back\", out)")
  936.         print ("rs.setBundledOutput(\"back\", 0)")
  937.         print ("in = rs.getBundledInput(\"front\")")
  938.         print ("if colors.test(in, colors.white) == true then")
  939.         print ("print (\"White is on in front\")")
  940.         print ("else")
  941.         print ("print (\"White is off in front\")")
  942.         print ("end")
  943.         pressany()
  944.       end
  945.     end
  946.     if chapter == 9 then
  947.       print "Your Goals:"
  948.       print ""
  949.       print "--Use the program hello--"
  950.       print "* Create an event loop"
  951.       print "* Print the char that was pressed"
  952.       print "* Stop the loop when the q key is pressed"
  953.       print "* Stop the loop if the redstone event happens"
  954.       print "* Run your program!"
  955.       print ""
  956.       print "You can type \"example\" at anytime to see the correct syntax."
  957.       print "quit will exit the sim early."
  958.       print ""
  959.       term.write (">")
  960.       input = io.read()
  961.       if input == "quit" then
  962.         break
  963.       elseif input == "edit hello" then
  964.         shell.execute("edit", nil, "tmptut")
  965.       elseif input == "hello" then
  966.         shell.execute("tmptut")
  967.         pressany()
  968.         term.clear()
  969.         term.setCursor(1,1)
  970.         print "Did your program work as you expected?"
  971.         print ""
  972.         print "Press [ENTER] to end the simulation."
  973.         print "Press Any Other Key to go back and work on your program."
  974.         local param1 = getCh()
  975.         if param1 == keyboard.keys.enter then
  976.           break
  977.         end
  978.       elseif string.lower(input) == "example" then
  979.         term.clear()
  980.         term.setCursor(1,1)
  981.         print ("term.clear()")
  982.         print ("term.setCursor(1,1)")
  983.         print ("while true do")
  984.         print ("event, param1, param2 = event.pull()")
  985.         print (" if event == \"redstone\" then")
  986.         print (" break")
  987.         print (" end")
  988.         print (" if event == \"char\" and param1 == \"q\" then")
  989.         print (" break")
  990.         print (" else")
  991.         print (" print (\"You pressed - \"..param1)")
  992.         print (" end")
  993.         print ("end")
  994.         pressany()
  995.       end
  996.     end
  997.     if chapter == 10 then
  998.       print "Your Goals:"
  999.       print ""
  1000.       print "--Use the program hello--"
  1001.       print "* Ask the user for their first name."
  1002.       print "* Ask the user for their last name."
  1003.       print "* Combine the 2 strings using a function"
  1004.       print " return the result into the fullname variable"
  1005.       print "* Show the user their full name"
  1006.       print "* Run your program!"
  1007.       print ""
  1008.       print "You can type \"example\" at anytime to see the correct syntax."
  1009.       print "quit will exit the sim early."
  1010.       print ""
  1011.       term.write (">")
  1012.       input = io.read()
  1013.       if input == "quit" then
  1014.         break
  1015.       elseif input == "edit hello" then
  1016.         shell.execute("edit", nil, "tmptut")
  1017.       elseif input == "hello" then
  1018.         shell.execute("tmptut")
  1019.         pressany()
  1020.         term.clear()
  1021.         term.setCursor(1,1)
  1022.         print "Did your program work as you expected?"
  1023.         print ""
  1024.         print "Press [ENTER] to end the simulation."
  1025.         print "Press Any Other Key to go back and work on your program."
  1026.         local param1 = getCh()
  1027.         if param1 == keyboard.keys.enter then
  1028.           break
  1029.         end
  1030.       elseif string.lower(input) == "example" then
  1031.         term.clear()
  1032.         term.setCursor(1,1)
  1033.         print ("term.clear()")
  1034.         print ("term.setCursor(1,1)")
  1035.         print ("function combine(s1, s2)")
  1036.         print ("result = s1..s2")
  1037.         print ("return result")
  1038.         print ("end")
  1039.         print ("write(\"What's your first name? \")")
  1040.         print ("firstname = io.read()")
  1041.         print ("write(\"What's your last name? \")")
  1042.         print ("lastname = io.read()")
  1043.         print ("fullname = combine(firstname, lastname)")
  1044.         print ("print (\"Hello \"..fullname)")
  1045.         pressany()
  1046.       end
  1047.     end
  1048.   end
  1049. end
  1050.  
  1051. mainmenu()
  1052.  
  1053.     © 2019 GitHub, Inc.
  1054.     Terms
  1055.     Privacy
  1056.     Security
  1057.     Status
  1058.     Help
  1059.  
  1060.     Contact GitHub
  1061.     Pricing
  1062.     API
  1063.     Training
  1064.     Blog
  1065.     About
  1066.  
  1067. Press h to open a hovercard with more details.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement