Jump to content




Configurable Quiz Game


  • This topic is locked This topic is locked
2 replies to this topic

#1 legomaniack

  • New Members
  • 7 posts

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.

-- 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


#2 Casper7526

    OG of CC

  • Members
  • 362 posts

Posted 09 February 2012 - 01:38 AM

Looks like that randomizetable function came in handy! Great work!

#3 legomaniack

  • New Members
  • 7 posts

Posted 09 February 2012 - 02:47 AM

thanks!

small update, forgot a clear screen.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users