This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
_OrangeJuice_'s profile picture

Cluedo Program

Started by _OrangeJuice_, 05 June 2013 - 08:37 PM
_OrangeJuice_ #1
Posted 05 June 2013 - 10:37 PM
Hey i'm trying to make a Cluedo game.

I would like to know how i can make a database that saves files .
How to make a Fill in form for the answers and that saves it to the database.
a program that compares the fill in form to a Answer list and gives points to the player.
And saves the points to a scoreboard file in the database.(Print Version and dataversion)
And i want to have security on the terminal that grants only me acces to the every.
And allows otherpeople to fill in the form and watch the scoreboard

I know it's a lot ^^ but it would certainly be cool to have this program for adventure maps .
also i'm making this for a multiplayer server i play on (it has pastebin enabled)

Thanks in advance :D/>/>
Lyqyd #2
Posted 05 June 2013 - 10:46 PM
Split into new topic.
Bubba #3
Posted 05 June 2013 - 10:55 PM
I would use tables and serialization. Something along the lines of this:


local questions = {
  [1] = {"What is the color of the sky?", "blue"};
  [2] = {"What is the tallest mountain on earth?", "Mt. Everest"};
}

local answers = {} --#Store the user input here

for index, tbl in pairs(questions) do --#For every single question in the questions database do
  local question = tbl[1] --#Get the text value of the question
  local answer = tbl[2] --#Get the text value of the answer

  term.clear() term.setCursorPos(1,1)
  write(question)
  local input = read() --#Get our user input

  answers[index] = input --#Insert the user input into the answers table in order to save it later
  if input == answer then --#If they had the correct answer then continue with the program
    term.setCursorPos(1,2)
    write("Well done!")
    os.pullEvent("key")
    --#Implement awarding points here somehow
   else --#If they had an incorrect answer then...
     term.clear() term.setCursorPos(1,1)
     term.write("Sorry! Game over...")
     break --#Break out of the for loop
  end
end

local function saveAnswers() --#Save all of the users answers to a file
  local f = fs.open("some_file", "w")
  f.write(textutils.serialize(answers)) --#textutils.serialize converts a table into text for easy saving
  f.close()
end

saveAnswers()

It's not really inserting the answers into a super user friendly format, but you can open the file and convert it straight back into a table so it's still nice. You can read up more on textutils.serialize and its counterpart textutils.unserialize on the wiki.

As to the security, look into some encryption APIs that are located in the programs/APIs section. There are a few gems that will make things easy for you.

Obviously this is not exactly what you want, but with some creative thinking I'm sure you can make it work to do whatever you want :)/>