Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Tutor V3 - Made by Rolcam")
- --https://pastebin.com/u/Rolcam
- -- Auto detects monitor
- tSides = {"left","right","bottom","top","front","back"}
- for i = 1, #tSides do
- monitor = peripheral.wrap(tSides[i])
- if monitor then
- side = tSides[i]
- break
- end
- end
- term.redirect(peripheral.wrap(side))
- -- ComputerCraft Programming Tutorial V2 by Rolcam
- os.pullEvent = os.pullEventRaw
- term.clear()
- -- Resets Screen
- function reset()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- reset()
- -- Section 1 - Intro
- print("Section 1: Program Introduction \n ")
- print("This is a crash course on coding in ComputerCraft")
- print("Some things to note: the IDE (or programming environment) IS case sensitive. \"term.clear()\" will work but \"tErm.clear()\" won't for example.")
- print("\"term.setBackgroundColor\" will work, but \"term.setbackgroundcolor\" won't.")
- print(" ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 2 - Basics
- print("Section 2: Basic Commands \n ")
- print("term.clear() - Clears the entire screen")
- print("This will also fill the screen with the background color selected")
- print("sleep(#) - Pauses the program for \"#\" number of seconds")
- print("term.setCursorPos(1,2) - Sets the cursor to the position listed. Note the comma separating the numbers. The first number is X position, the second is Y position")
- print("break - Used to break out of a loop \n ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 2.1
- print("Section 2.1: Variables \n")
- print("a = \"test\" - Declares a variable \"a\" as a string with the text \"test\" ")
- print("a = 2 - Declares a variable \"a\" with a value of 2")
- print("It is highly recommended you declare variables like so: local a = <value> \n ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 3 - Text
- print("Section 3: Text \n ")
- print("print(\"Text\") - Displays text on a new line \n ")
- print("write(\"Text\") - Writes text on the same line. Useful for multi-colored text or showing variables")
- print(" ")
- textutils.slowPrint("textutils.slowPrint(\"Text\") ")
- term.setCursorPos(29,8)
- term.write("- Slowly prints text.")
- print("Try to use this sparingly. It can get old rather quickly. \n ")
- print("Note: You need to use quotes for the text commands. If you don't, it sees the text as a variable and it will show the value of that variable instead. Be careful and keep that in mind. \n ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 4 - Colors
- print("Section 4: Colors \n ")
- term.setTextColor(colors.cyan)
- print("term.setTextColor(colors.cyan) - changes the color of any new text being printed. It WON'T change the text already on screen")
- term.setBackgroundColor(colors.gray)
- print("term.setBackgroundColor(colors.gray) - Changes the background for new text being printed")
- print("to change the entire background, use \"term.clear()\" after this")
- print("You can use any of the 16 vanilla dye colors for the colors utility")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- print(" ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 5 - If/Else Statements
- print("Section 5 - If/Else Statements \n ")
- print("These are useful in more complex programs. They provide basic logic to a program. \n ")
- print("if a == 1 then - If the variable \"a\" equals 1, then the program will print \"Hello\"")
- print("print(\"Hello\")")
- print("elseif a == 2 then - Otherwise, if \"a\" is equal to 2 then the program will print ")
- print("print(\"Goodbye\")")
- print("\"else\" - Otherwise the program will print \"Hello World\"")
- print("print(\"Hello World\")")
- print("end - Designates the end of the if statement \n ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 6 - Loops
- print("Section 6 - Loops \n ")
- print("These are also useful in more complex programs. They can provide logic to a program.")
- print("Remember to always put \"end\" as the last line to close the loop\n ")
- print("while a == 1 do - While the variable \"a\" is equal to 1, keep looping /n")
- print("for <start>, <end>, <interval> do - this is a more advanced loop.")
- print("for a = 1, 10 do - Interval is optional. It sets a local variable to the loop \"a\" as 1 and")
- print("stops looping when \"a\" is equal to 10 \n ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 6 Cont.
- print("Section 6 - Loops cont.\n ")
- print("repeat - Opposite of a while loop. This will keep repeating until the condition is true")
- print("blah blah blah - fake code stuff")
- print("until a == 5 - This is used to close this loop instead of \"end\"")
- print("If the above condition is true, the loop will end. As this is on the bottom, this loop will run at least once")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 7 - Redstone
- print("Section 7 - Redstone \n ")
- print("rs.setOutput(\"Side\", true/false) - Sets the redstone output for the computer. Sides: top, bottom, left, right, front, back")
- print(" ")
- print("rs.setBundledOutput(\"Side\",colors.red) - Sets the bundled redstone output for a computer. Only one state can be set per side")
- print(" ")
- print("To set multiple colors, use colors.combine(colors.red, colors.blue). This will set the output of red and blue to true.")
- print(" ")
- print("To turn off the bundled output, just use \"0\" instead of colors")
- print(" ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 7 - Redstone Continued
- print("Section 7 - Redstone cont. \n ")
- print("redstone.getInput(\"back\") - Gets state of redstone input on the selected side as a Boolean (True/False)")
- print(" ")
- print("redstone.getOutput(\"back\") - Gets state of redstone output to the selected side as a Boolean")
- print(" ")
- print("redstone.getBundledOutput(\"side\") - Gets the colored cables that are active")
- print(" ")
- print("redstone.testBundledInput(\"side\", color) - Gets state of bundled cable input on the selected side as a Boolean")
- print(" ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- -- Section 8 - Example Program
- print("Running Example Program...")
- print("sleep(1) is used for the pause between commands")
- print(" ")
- print("Redstone Example Program")
- print(" ")
- print("Please put a redstone powered device like a door or lamp to the left of the computer")
- print("<---------")
- print(" ")
- print("Touch the screen once the device is placed")
- os.pullEvent("monitor_touch")
- term.clear()
- term.setCursorPos(1,1)
- print("rs.setOutput(\"left\", true)")
- rs.setOutput("left", true)
- sleep(1)
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- print("rs.setOutput(\"left\", false)")
- rs.setOutput("left", false)
- print("end of redstone demo")
- print(" ")
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- reset()
- term.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement