My student is creating a game where one sprite turns into another and another, eventually showing 2-3 cars that are going to race.
A light appears which goes from red to yellow to green, and while each color appears a beeping sound occurs followed by a longer beep when the cars go.
The problem is that when the code is run, instead of the 4-second beep sequence playing, you hear a solid tone that never stops. It’s as if every time the routine runs, the sound starts to play but gets cut off as the code routine ends and starts again. The result is that something like a 1/100th of a second of sound plays from the start of the YouTube sound, and then the code is run again, causing another tiny burst of sound. This continues over an over in such a way that the tone played sounds like it goes on and on instead of the three beeps for red, yellow, and green. I hope that makes sense.
Originally, the student had the sound somewhere in lines 30-80, but all he got was the constant single, ongoing sound.
I thought that the beginning of the sound kept playing because it was in some form of loop. So the student put the sound at the end of the code - outside the draw loop, but nothing worked then.
YouTube Sound: Mario Kart Race Start - Gaming Sound Effect (HD) - YouTube
My student and I were trying to figure out why the code played the sound but not all of it. Is there a standard amount of time the a code routine allows for the playing of a sound each time it runs through the routine? How can you make the code stop for the whole sound file to play before going on with the routine?
(Also, this came up during the discussion: Is there a “repeat routine” command/loop we can use when writing the code? In the Hour of Code lesson with Elsa, there is a loop where you can write in how many times a routine should be run - and that was easy. But we can’t find something that helpful - ! - in CSD. Are we missing something?)
Thank you, very much.