Friday, June 29, 2012

Ask random questions

This week I tried to write a program to set ans ask random questions in a Scratch program.
Since we cannot read from a text file, I set the questions and answers in a list beforehand:

This will create two lists like this:

I made a third list to remember which questions have been asked before so that I do not ask the same question twice.  I added the number of the question that I have asked to this list and then checked whether a number is already on this list before I asked it again.

On the stage, I displayed all the possible answers as follows, so that the player only has to input the number of his choice:

The code to ask 5 random questions and check whether the answers are correct:

Note: you can simply check whether Answer = questionNumber to see is the answer is correct.

1 comment:

  1. You can actually load from a text file by right clicking the empty list and then select import.
    When you close your application it will retain the information in the list.