Jump to content
Sign in to follow this  

Newbzor to scriptingz.

Recommended Posts


I used to be pretty decent with scripting, that was 3 years ago, I forgot everything I knew, and am slowly getting back into the wonderful world of sctipts. I'll stop my rant and get to the point.

I want to make a "test" with "multiple choice answers".

More detailed description: I want a test that displays a random question from my list of questions, and shows four different choices which will also be listed somewhere in relation to each question, if that's even possible.

So what I'm asking, is where would I start, if this were a possible option to include into a script. And how difficult would it be?

Help is appreciated, thanks in advance.


Share this post

Link to post
Share on other sites

There are various ways that you could do this. One way would be to put all the questions and answers into a multidimensional array and find a way to shuffle it. However that might be a little complicated.

A simpler way would be to put the questions and answers into text files, making sure that both the question and correct answer appear on the same line in each file. You might also want to create a separate file for each incorrect answer. You can select the question you want by using the Random function to return an integer. Then read the question and compair the answer given with the correct answers file. The advantage of this method is that you can easily add new questions and answers without having to change anything in your code.

One thing I forgot to mention: You will have to find a way to avoid repeating the same question.

Edited by czardas

Share this post

Link to post
Share on other sites

Personally i'd use a 2 dimensional array.

First element for index of question, second element to determine question, answers 1-4, and correct answer number.

Use random number generator to determine which question to ask and answers to display, and test against answer number.

If you need to avoid repeating questions, use a sixth array element to indicate "asked" and test for this before asking the question.

The only slightly tricky bit would be reading your data into your array



Just re-read that, and it doesn't scan well, so example:

$questions[1][1] = "what is 5x4"

$questions[1][2] = "15"

$questions[1][3] = "20"

$questions[1][4] = "30"

$questions[1][5] = "24"

$questions[1][6] = "3"

generate a random number ($rand) to use for your first[] as the question to ask, display the answers in [$rand][2-5] and test if the answer = $questions[$rand][$questions[$rand][6]]

Edited by Remnant

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this