Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is part of a Computercraft Programming Teaching Program
- 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
- -- Clears the monitor screen
- function reset()
- term.redirect(peripheral.wrap(side))
- term.clear()
- term.restore()
- end
- loop = 0
- rep = 0
- prog = 0
- -- Generates test 1
- function gen1()
- print("Generating test program 1...")
- e = fs.open("test", "w")
- e.writeLine("[ ] <----- ")
- e.writeLine("for e,0,-1 do")
- e.writeLine("term.clear()")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("print(\"The number is: \"..e)")
- e.writeLine("end")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- -- Generates test 2
- function gen2()
- print("Generating test program 2...")
- e = fs.open("test", "w")
- e.writeLine("e = 5")
- e.writeLine("while e > 0 do")
- e.writeLine("term.clear()")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("e = e - 1")
- e.writeLine("runTime = os.clock()")
- e.writeLine("[ ] <----- ")
- e.writeLine("sleep(0.1)")
- e.writeLine("end")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- -- Generates test 3
- function gen3()
- print("Generating test program 3...")
- e = fs.open("test", "w")
- e.writeLine("term.clear()")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("e = 10")
- if prog == 0 then
- e.writeLine("[ ] <----- ")
- else
- e.writeLine("[e = e + 3]")
- end
- e.writeLine("print(e..\" = 13\")")
- e.writeLine("Print(\"Hello World\")")
- e.writeLine("Print(\"What's your name?\")")
- if prog == 1 then
- e.writeLine("[ ] <----- ")
- else
- e.writeLine("[ ]")
- end
- e.writeLine("end")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Lesson 3 Test - Variables \n ")
- print("This is a basic knowledge test")
- print("You will be asked to complete a program by inserting a line of code")
- print("You aren't timed or scored and you have unlimited attempts \n ")
- print("Press the enter key when ready")
- read()
- gen1()
- loop = 1
- reset()
- -- Test 1 of 3
- while loop == 1 do
- rep = 6
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 1 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- print(" \nDeclare the variable \"e\" with a value of 10")
- print("Type \"help\" for a help or \"skip\" to skip")
- input = read()
- if (input == "e=10") or (input == "e = 10") then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("Not quite. Try again")
- sleep(2)
- end
- end
- gen2()
- loop = 1
- reset()
- -- Test 2 of 3
- while loop == 1 do
- rep = 9
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 2 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- print(" \nPrint the value of \"runTime\"")
- print("Type \"help\" for a help or \"skip\" to skip")
- input = read()
- if input == "print(runTime)" then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif input == "print(\"runTime\")" then
- print("Close, but not quite")
- print("You want to print the value of the variable, not the variable's name")
- print("Try Again")
- sleep(3)
- elseif input == "print(runtime)" then
- print("Close, but not quite")
- print("Remember, variable names are case sensitive")
- print("Try Again")
- sleep(3)
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- end
- gen3()
- loop = 1
- reset()
- -- Test 3 of 3
- while loop == 1 do
- rep = 9
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 3 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- if prog == 0 then
- print("Make the variable \"e\" equal to itself plus 3")
- input = read()
- if (input == "e = e + 3") or (input == "e=e+3") or (input == "e = e+3") then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- reset()
- prog = 1
- gen3()
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping...")
- prog = 1
- gen3()
- reset()
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- else
- print("Use the read command to declare the variable \"name\"")
- input = read()
- if (input == "name = read()") or (input == "name=read()") then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif (input == "Name = read()") or (input == "name = Read()") or (input == "Name = Read()") then
- print("Close, but not quite")
- print("Remember, everything is case sensitive")
- print("Try Again")
- sleep(4)
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.lime)
- print("Congrats, you have competed all three tests")
- sleep(3)
Add Comment
Please, Sign In to add comment