Search code examples
mit-scratch

Scratch quiz game randomizer not working


I have an inventory of 30 variables that are randomly selected. When one variable is chosen a question that corresponds with that variable should appear. Instead no matter which variable is chosen, the block at the end of the code is chosen. I even got rid of the randomizer so I could choose which variable was chosen, but the code still went all the way to the bottom. How can I fix this?

Here is a screenshot of part of the code:

enter image description here


Solution

  • The problem with your code is that none of your if blocks can ever evaluate to false. After all, Inventory does contain every of it's items. Therefore every say is executed, but everey output is replaced by the subsequent one. Due to the speed with which this happens, you can only see the last one.

    A solution is to select an item into another variable and compare this variable to the list, like so:

    enter image description here