Posted 09 February 2012 - 01:36 AM
This is my first useful lua program, hope you enjoy!
Its a quiz game, that asks you questions in a random order. questions are configurable
originally created for vocab study.
Its a quiz game, that asks you questions in a random order. questions are configurable
originally created for vocab study.
-- Quiz game by legomaniack
-- edit the questions to your liking
-- uses: vocab study, quiz your friends,
-- test you memory... ect.
-- numbers is just 1 through # of questions
numbers = {1, 2, 3}
-- qs is the questions.
qs = {"2 + 2", "8 + 1", "7 - 4"}
-- as is the awnsers to the questions
-- order matters!
as = {"4", "9", "3"}
term.clear()
term.setCursorPos(1,1)
-- randomize table funtion written by casper:
function randomizetable(tbl) -- send a table to this function
for x = 1, #tbl + 0 do -- replacing the 0 with another # will jumble the table up more times but isn't really needed
rnd = math.random(1, #tbl)
table.insert(tbl, #tbl + 1, tbl[rnd])
table.remove(tbl, rnd)
end
return tbl
end
while true do
textutils.slowPrint("Welcome to the Quiz game!")
sleep(1.5)
order = randomizetable(numbers)
correct = 0
for i = 1, #order, 1 do
print("Question number "..i..":")
print(qs[order[i]])
awnser = io.read()
if awnser == as[order[i]] then
correct = correct + 1
print()
end
end
term.clear()
term.setCursorPos(1,1)
print("Total correct: "..correct.." out of "..#order)
print("Play again?")
print("[y]es or [n]o")
again = io.read()
if again == "y" then
term.clear()
term.setCursorPos(1,1)
elseif again == "n" then
term.clear()
term.setCursorPos(1,1)
break
else
print("invalid input. defalting to no.")
sleep(3)
term.clear()
term.setCursorPos(1,1)
break
end
end