[Solved] Prevent Multiple Button Click

Hi

I was going through the Quiz App video and noticed a small issue. When you click the correct answer I noticed I could still click the button multiple times until the next question appears and this obviously increases the score.

How do I block the click feature on a button for few seconds before the next question is displayed.

1 Like

Hi there,

Good catch!

Buttons have a property called ‘Disabled’ which stops them from responding to being clicked.

disableButton

When an answer is selected, you could disable all of the Buttons on your Screen by setting ‘Disabled’ to true. When the next question is loaded, you can enable all of the Buttons again by setting 'Disabled to false :grinning:

2 Likes

ahhh mama mia, I was just looking at that option while searching. Thanks

1 Like

The only down side to this is the disable button option removes the answer color highlights.

Can we have a disable click feature rather than disable button alone?

1 Like

If you want to keep the appearance of the Button intact, you could use a Boolean: a variable whose only possible values are true or false.

You can initialize an app variable answerNotSelected to true.
When the user has selected an answer, set answerNotSelected to false.
When a new question opens, set answerNotSelected to true again.

Then just put whatever blocks you have for your Buttons inside an if block that says ‘if answerNotSelected’.

This will disable the effects of your Button once an answer has been selected without changing its appearance.

3 Likes

Block view of what you need to do based on @jane reply:

  1. First initialize a variable and set it to FALSE. I called mine “answerSelected”. This means I have not clicked on any answer button, so everything is normal.

image

  1. Next on button click block, add an if statement and check if the variable is still false. If FALSE, then everything inside the block will take immediate effect

  2. Immediately after the IF statement, add set variable block to TRUE. This would ensure that if you try to click the button immediately while the answer is been processed, nothing will happen to the button

image

  1. Lastly you need to set the variable back to FALSE so we can click on buttons again. Add this at end of the “Update quiz for each question” block

image

Hope this helps visually.

The next bit I need to figure out is when I exit question halfway and come back to it, I want it to restart question from beginning and not from where I last was.

2 Likes

Looks great!

What does starting a question from the beginning mean here?

1 Like

Basically in my app, I have an Exit screen

image

So when I click on YES, it takes me to Home Screen
Click on No, it takes me back to game screen

The issue with Home Screen which is also my Menu screen with a Play button which goes to game screen, is when I click Play, it takes me to game screen but continues from last question before I exited rather than restarting questions from 1

1 Like

Ah actually I think I found an answer in block in Game Over screen. Reset question variable back to 1 and also score.

1 Like

SO you want to restart the whole quiz - that makes more sense :grin: resetting the question variable to 1 is exactly what I’d recommend!

No it didn’t work as expected. When I click Yes, it resets question back to question 1 but then the score at first resets to 0 but then changes to last score

1 Like

Can you message me a share link to your app so I can see what your blocks look like?