Music loops too many times when game ends

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

Link to the project or level: https://studio.code.org/projects/gamelab/G-24A-VeYjVkATt2ruTlpVNflk6jpfRetwoN1BM0mz8
What I expect to happen: [When game ends music changes to either losing or winning
What actually happens: [Music does play on winner or loser screen but both play over and over forever and then the game freezes and you have to refresh to stop sound
What I’ve tried: changing sound, moving, changing false/true options, adding a stop music
All other sounds are correct.

Didn’t want to leave you too long without an answer on this one, but I have been looking at it off and on the last 24 hours and still haven’t found a solution, but I will still keep looking at it. I am suspecting that because most of the sounds are called from the draw loop or from a function inside the draw loop that there is one or more sounds that are repeatedly executing and that is causing the issue. I may start removing one sound at a time to see if I can find the offending sound or sounds. What makes it even more confusing to me is that when I start the game, I sometimes get one sound and sometimes another and even refreshing the browser doesn’t always fix it, so this one is a bit tricky, but I’ll still look at it again when I get a minute and see if I can’t see something that is escaping me.

Mike

Thank you so much! :smiley: I greatly appreciate your help and trying.

My student has been working on it all week trying to debug too but she’s a “newbie” at coding and I’m not that much more experienced either.

Our school is on semester break starting tomorrow through Jan 6 so there’s no immediate rush.

THANKS AGAIN!

It looks like the problem is that the draw loop is running the winnerWinner or endGame function over and over, so the sound is playing over and over. Can you try doing something similar to how you saved the game state in order to create the start screen? For example, have a won variable that is originally set to false. Then, inside the winnerWinner function, instead of just checking to see whether (score >= 10), check for ((score >= 10) && (won ==false)). Then set won to true inside that code.

Elizabeth

2 Likes

Thanks for the reply. We just got back from winter break. I’ll get back with you after we tried it. Thank you so much for the suggestion!

1 Like