Discuss Scratch

johnnybearjr
Scratcher
38 posts

I'm having trouble muting music in my game.

HELLO

I'm making a game where one of the features is choosing what music you want to listen to. There are 15 songs. I have a button for each song individually and a button for turning the music off. The thing I'm having trouble with is the “Play All” button.

When play all button is clicked on it sends a broadcast to the backdrops, “where the songs are located” and the script in backdrops does this:

when I receive [ play all]
play sound [ random song] until done
play sound [ another song] until done
play sound [ more song] until done

I also have a “music off” button. The music off button works if I listen to a song individually, but if I have the play all running it just skips to the next song and starts playing that. I want it to just stop playing the music with just one click not just skip to the next song.

Here's the recreation of my music off button:

when this sprite clicked
stop all sounds
set [ song] to [0]

I'm thinking of just removing the play all button, but maybe this thread can save it. If you think removing the play all is the best step don't be afraid to tell me. My apologies for not knowing how to connect the scratch blocks together. Also, I'm sorry if this is an easy fix and I just don't know it. I appreciate any help or suggestions you can give,
- johnnybearjr
KaneryU
Scratcher
85 posts

I'm having trouble muting music in my game.

OK I will save it! don't delete the code, ill edit it with the answer:

when I receive [ Play All]
set [ Song_Name] to [3]
play sound [ sound] until done
change [ Song_Name] by (-1)
play sound [ Sound] until done
change [ Song_Name] by (-1)
play sound [ Sound] until done

when this sprite clicked
repeat (Song_Name)
stop all sounds
end

EXPLANATION:
The Song_Name var, says how many songs have been played, in decreasing order, so in the repeat block, if three songs haven't been played, the songs need to be muted three times, and the var is 3, repeat 3 times, same for 2, same for 1 time!

Tell me if it doesn't work!

Last edited by KaneryU (Feb. 28, 2021 06:16:04)

johnnybearjr
Scratcher
38 posts

I'm having trouble muting music in my game.

Thank you!

I used a variation of the code you did, and somehow it worked! My biggest thank yous to you! I'll put this thread and your name in the notes and credits of the game. The first script I had to change to something like this:

when I receive [ play all]
stop all sounds
set [ Songname] to [15]
if <(SongName) = [15]> then
play sound [ examplesong] until done
change [ SongName] by (-1)
end
if <(SongName) = [14]> then
play sound [anothersong] until done
change [ SongName] by (-1)
end
etc


For the muting script, I used the same thing, but I had to add a wait block.

when this sprite clicked
repeat (SongName)
stop all sounds
wait (0.01) secs
end

Thank you for helping me fix this, you're very kind! You're the reason why the play all button works now! Thank you! My game will release later today. It's a cookie-clicker game.

Powered by DjangoBB