TNT Basic Forums > Games In Progress
Developing a trivia quiz
< Last Thread     Next Thread >
Thread        Post A Reply

01-13-2007 05:33

Posted by:

South Dakota

Find more posts by JHVipond

In my continuing experiments with TNT Basic, I've decided to try programming a multiple-choice trivia quiz. So far I have two integer variables, qnum and score, and three string variables: answer[4], choice[4], name and question.

For each question, the program would read five lines: the question itself, the correct answer and three wrong answers. Here's the preliminary program flow:

1. Set score to 0 and qnum to 1. Variable qnum is a pointer to the next unused question in the file.
2. Ask the player to enter his/her name.
3. Open the data file.
4. Read the question text and four answer choices from the data file. Let answer[0] be the correct answer and answer[1] through answer[3] be the wrong answers.
5. Shuffle the answer choices so that the correct answer does not always appear first. (This, to me, is one of the hardest parts to program. For example, choice[0] is the first answer choice displayed, but the value of answer[0], the correct answer, may be assigned to choice[2], the third choice displayed. Put another way, the answer values are always read in order 0,1,2,3 but may be displayed in order 1,3,0,2.)
6. Display the question. Below it are four buttons, each labeled with a different answer choice.
7. If the player chose the correct answer, ring a bell and add 1 to the score. Go to step 9.

print "Correct answer!"

8. Sound a buzzer and indicate the correct answer. Do not deduct points for a wrong answer.

print "Sorry, the correct answer was:"
print answer[0] ' Remember, the correct answer was read first

9. Add 1 to qnum.
10. Repeat from step 4 until all questions in the file have been used.
11. Display the player's final score.

Have I overlooked anything? Is there an efficient way to randomize the order in which the four answer choices are displayed for each question? I want to be able to add categories later, for use in TV-style games.

01-13-2007 14:54

Posted by:

Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Is there an efficient way to randomize the order in which the four answer choices are displayed for each question?

Hmmm i have an idea, though there's probably a better way. Anyway, if it works, who cares? ;)

I'd have an array containing 0,1,2,3 - and then randomly swap them.

code mockup: (not tested)

int order[4]

int n
int id1, id2, swapvalue

for n=0 to 10 ' repeat ten times


if id1<>id2

swapvalue = order[id1]
order[id1] = order[id2]
order[id2] = swapvalue

end if


and after display them in the order contained by 'order'

02-05-2010 20:55

Posted by:

South Dakota

Find more posts by JHVipond

New approach

I've begun trying a new approach to my trivia quiz project. Instead of trying to randomize the order of answer choices for each question, I'm assigning the integers 0, 1, 2 and 3 to the answer choices. Here's my new question format:

Text of question
Choice 0
Choice 1
Choice 2
Choice 3
Integer for correct answer (0..3)

The player is expected to press a key (1, 2, 3 or 4) for the desired answer; key 1 is for choice 0, key 2 for choice 1 and so on. I've uploaded the current version of the game to my MidcoNet site.

But now I have a new problem: How do I tell TNT Basic where my question file is, and that it's a plain text, read-only file? The following code generates errors:

int quizfile
quizfile=open file (questions.txt,false,TEXT,Text)

If I can get this working, I may add categories. Any help would be appreciated.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.