Sound in conditional?

My students are creating their Interactive Card (Lesson 17). Several have if statements where sound “music” plays as a result. However it’s staticky unless it’s outside the drawLoop. Any suggestions on how to make this work?

It worked in this one from last year (2019-2020) Code.org - Game Lab
But not this one this year (2020-2021) Code.org - Game Lab

Any suggestions?!?!

@gagwu,

I have found that when you use the “stopSound” block before using the playSound block, it works very well. Your example from last year is using that technique.

What is happening is that the draw loop wants to repeat all actions. That includes playing sounds. So, if you have a stopSound, it will stop the current iteration of the sound before starting to play it again.

Let us know if that helps. I haven’t tried it in your “this year” example, but it should work.

Mike