Summer is an odd time. With no ice hockey matches to attend our thoughts turn to other subjects, such as why does RefSignals sometimes repeat questions? I've been asked a few times about how to stop it doing this, so here is a solution. RefSignals is an Android app built with Google App Inventor for Android that quizzes you on the signals made by referees during ice hockey matches. In February I wrote about this app and published the source code so that people could take it and use it as the basis for their own quiz apps. The response was great and the app has been remixed for all sorts of subjects so I hope this will come in useful.
The RefSignals app picks an entry at random from a bank of twenty-five ice hockey penalties as the basis for a question where the user is asked to correctly identify the penalty that the referee is signalling in the picture. The quiz is multiple choice, so three options are presented where one is the correct answer and two the wrong answer. In the original app there was nothing to prevent the same penalty being picked more than one to be the basis of a question, so we need to get it to remember the penalties it has picked and not ask about them again. These instructions show you how to update the original app, but up to date source code is attached.
In the Blocks editor define a new variable called penalties_taken. Go to the Lists drawer and select Make a list and drag it into your new variable. This just means the variable will contain an empty list when it is created. This variable will eventually contain the index number of the penalties used so far in the quiz for questions. You new variable block should look like the one below.
Now find the NextButton.Click block. The first if block is run when we are on the first question of the quiz, we need to add some logic to reset our list of penalties that have been used for questions, otherwise if the user runs the quiz more that once we will run out of penalties to ask them about. Add a block to set the value for the variable this_penalty to zero, then add a block to set the value of the penalties_taken by dragging a make a list block into it and then making that item in the list a zero. The top of your NextButton.Click block should now look like this:
Our pickPenalty block can now be amended to prevent repeated questions about the same item. The logic here is to pick a penalty and then check if it is in the penalties_taken list. If it is pick another penalty, check again and so on. We can implement this logic with a While block. While the current penalty is in the list generate another penalty. The variable this_penalty will always be set to the last penalty asked about, so the while loop will run at least once. Of course the first question is a bit different as there are no entries in the list or current penalty, so we force the logic inside the loop to run in this instance by deliberately setting this_penalty to zero and making the first item in the penalties_taken block a zero too. Your pickPenalty block should look like the one below.
If this doesn't make sense at first have a look at the blocks in the Editor and consider the order that they are run in. See if you can follow the instructions yourself. It might also help to watch the penalties_taken list being populated. You can do this by going to first Is in List? Block and right clicking over the penalties_list block next to it. Select Add Watch and you should see a balloon that will show the list filling up as the quiz runs.