Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » The "if" block problem.
- notaweirdperson
- New to Scratch
10 posts
The "if" block problem.
It's hard to explain in detail but I'll try my best. I want to make the player spin 3 pictures and if the pictures are all in the correct direction, a sound will be played. After it happens, the player won't be able to spin the pictures again. So if one of the pictures are in the correct direction, their variable will be set to 1. When all the pictures' variables are set to 1, it will play a sound. However, the “if” block doesn't work.
if <<[(variable)] = [1]> and <<[(variable 2)] = [1]> and <[(variable 3)] = [1]>>> thenThe problem is that the sound is never played. I checked all the variables tab and they are all set to 1, I put this under
play sound [ v]
end
when green flag clickedand it still doesn't work. If I put “forever” then it will play the sound forever, which is not what I want. Is this error caused something else in other scripts or am I missing something?
- deck26
- Scratcher
1000+ posts
The "if" block problem.
You need either a loop or a wait until so the script doesn't just skip past the if statement and never execute it.
For example
For example
wait until <<[(variable)] = [1]> and <<[(variable 2)] = [1]> and <[(variable 3)] = [1]>>>
play sound [ v]
- deck26
- Scratcher
1000+ posts
The "if" block problem.
You could also have used a forever loop with a ‘stop this script’ after the play sound block.
- helloworldbyeworld
- Scratcher
1000+ posts
The "if" block problem.
If you want the script to play a sound whenever all the variables are set to 1, you will need to use a forever loop and put the original if statement inside. Here’s a modified version of the original script that works:
when green flag clicked
forever
if <<(variable) = [1]> and <<(variable 2) = [1]> and <(variable 3) = [1]>>> then
play sound [ v]
set [variable v] to [0] // one of the variables will need to be set to something else so it does not keep playing the sound forever
end
end
Helloworldbyeworld | 1200+ posts
Have a great day
- Harakou
- Scratcher
1000+ posts
The "if" block problem.
Glad you found an answer! Since this is resolved, I'll close it to help highlight the answer and prevent future responses. If you need it re-opened, though, you can report this and ask. It worked, thanks!
- Discussion Forums
- » Help with Scripts
- » The "if" block problem.