Discuss Scratch

BananaKing2771
Scratcher
2 posts

Need help with gameover music

https://scratch.mit.edu/projects/740337401

I am making a game with my friend, and I need help with the music. I want it so when you get 0 lives, the main music stops completely, and the game over music starts. This is my first project, and it's pretty buggy and not the best, but hopefully it won't be so terrible in the future. Thanks for the help.
theforgottenwisp
Scratcher
100+ posts

Need help with gameover music

Maybe this?
when green flag clicked
forever
if <(lives) = [0]> then
stop all sounds
play sound [game over music v]
end
end
If you used a broadcast to signal when the player has zero lives, then you can just do this:
when I receive [game over v]
stop all sounds
play sound [game over music v]

Last edited by theforgottenwisp (Oct. 11, 2022 15:21:46)

nyankatpro
Scratcher
500+ posts

Need help with gameover music

The reason the game over music doesn't play is because of this part of the code:

 
when green flag clicked
show
set [lives v] to [5]
forever

if <(lives) > [1]> then
start sound [JerryTheme1(2.0) v] :: sound
play sound [JerryTheme1(2.0) v] until done

else
stop all sounds
end
end

When the code reaches the "play sound until done" block, it waits there until the song is finished. This means that the rest of the code only runs when the song is restarting. The easiest way to fix this is to put the main music in its own section:

when green flag clicked
repeat until <(lives) < [1]> //ends the loop once you run out of lives
play sound [JerryTheme1(2.0) v] until done //song will be stopped by the "stop all sounds" block
end

when green flag clicked
show
set [lives v] to [5]
wait until <(lives) < [1]>
stop all sounds
play sound [JerryGameOverTheme1(2.0) v] until done
BananaKing2771
Scratcher
2 posts

Need help with gameover music

Thank you so much for the help! I really appreciate it! I will be sure to credit you both!

Powered by DjangoBB