I'm very new to Computer Craft and programming in general and I'm really enjoying it. I decided to make a simple, little test program in which questions are asked by the computer and you don't proceed with the "game" unless you enter the correct answer.
I want there to be more than one acceptable answers, so I tried having the code look for "answerA or answerB or answerC" as shown in the code below:
--Function(s)
function riddle(question, answerA, answerB, answerC, extraText)
local ans = ""
print(question)
term.write("Answer: ")
ans = read()
if ans ~= answerA or answerB or answerC then
textutils.slowPrint("Wrong! Try Again!")
return false
else
textutils.slowPrint("Correct!".. x)
return true
end
end
--Main Program
textutils.slowPrint("Welcome to the Riddle 'Challenge'!!!")
textutils.slowPrint("Question #1: ")
while not riddle("What color is an apple?", "red", "green", "yellow", " Next Question...") do
end
textutils.slowPrint("Question 2: ")
while not riddle("What part of your body do you smell with?", "nose", "Nose", "Nose.", " Next Question...") do
end
textutils.slowPrint("Question 3: ")
while not riddle("What planet are you on right now?", "earth", "Earth", "Earth.", "") do
end
textutils.slowPrint("Congratulations! You are a 'genius'!")
However, when I have the code set up like this, it doesn't even accept any answers at all! I think it may be a problem regarding the multiple ors I wrote in the function, but I'm not sure. I would be grateful if someone could tell me exactly why my program doesn't accept any of the three possible answers when the questions are asked.
Thanks! (and tell me if I used too many "textutils.slowPrint"s :P/>)