Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Is There A Way To...?
- PlantStar-Alpineer
- Scratcher
20 posts
Is There A Way To...?
I'm developing/remixing a platformer with background music playing, and I want to have the music change after you finish level 20. The variable for what level you are on is ||LEVEL||.
Last edited by PlantStar-Alpineer (Nov. 25, 2017 02:44:17)
- SpaceDragon1
- New to Scratch
100+ posts
Is There A Way To...?
Maybe this?
After changing level
if <(level) = [21]> then
stop all sounds
play sound [ v]
end
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
Yes, it can be done. Simplest method is when level 20 is completed, stop all sounds then play the new sound.
Last edited by mstone326 (Nov. 25, 2017 02:46:57)
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- lokarz368
- Scratcher
27 posts
Is There A Way To...?
forever
if <(||LEVEL||) > [19]> then
stop all sounds
play sound [ v] until done
end
end
or of there are other sounds playing in the levels
repeat until <(||LEVEL||) > [19]>
if <(||LEVEL||) > [19]> then
stop all sounds
forever
play sound [ v] until done
end
end
end
- PlantStar-Alpineer
- Scratcher
20 posts
Is There A Way To...?
Well, what I have now is…
When flag clicked, clear graphic effects, switch backdrop to backdrop1, repeat until level is 21 (set volume to 100, play sound until done), if level is 21 then stop all sounds.
When flag clicked, clear graphic effects, switch backdrop to backdrop1, repeat until level is 21 (set volume to 100, play sound until done), if level is 21 then stop all sounds.
Last edited by PlantStar-Alpineer (Nov. 25, 2017 03:01:00)
- SpaceDragon1
- New to Scratch
100+ posts
Is There A Way To...?
The second will never do anything. If it is less than 19, then it will skip over the code, if it is 19 or more then it will keep looping until the level is less than 19 (which will not happen).forever
if <(||LEVEL||) > [19]> then
stop all sounds
play sound [ v] until done
end
end
or of there are other sounds playing in the levelsrepeat until <(||LEVEL||) > [19]>
if <(||LEVEL||) > [19]> then
stop all sounds
forever
play sound [ v] until done
end
end
end
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
Well, what I have now is…
When flag clicked, clear graphic effects, switch backdrop to backdrop1, repeat until level is 21 (set volume to 100, play sound until done), if level is 21 then stop all sounds.
That should work. To give more room for error, instead of is level = 21, do if level > 20. Gives a little room for error incase for some reason your code jumps from 20 to 22 for some reason.
if <(level) < [21]> then
play sound [game v] until done
else
stop all sounds
play sound [ending v] until done
end
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- PlantStar-Alpineer
- Scratcher
20 posts
Is There A Way To...?
Now I have…
When flag clicked, clear graphic effects, switch backdrop to backdrop1, if ||LEVEL|| > 20 then play sound until done else stop all sounds, but the music isn't… playing……
When flag clicked, clear graphic effects, switch backdrop to backdrop1, if ||LEVEL|| > 20 then play sound until done else stop all sounds, but the music isn't… playing……
- PlantStar-Alpineer
- Scratcher
20 posts
Is There A Way To...?
Now it's when ||LEVEL|| < 20, but the music is still playing after level 20.
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
The music will finish until done, then it won't start again. There are ways to fix that using clones but maybe easiest for now as you are just starting out, use a parallel loop (just another loop that will run at the same time to check if level is > 20, then have that stop all sounds. Not ideal but should work just fine.
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- lokarz368
- Scratcher
27 posts
Is There A Way To...?
The second will never do anything. If it is less than 19, then it will skip over the code, if it is 19 or more then it will keep looping until the level is less than 19 (which will not happen).forever
if <(||LEVEL||) > [19]> then
stop all sounds
play sound [ v] until done
end
end
or of there are other sounds playing in the levelsrepeat until <(||LEVEL||) > [19]>
if <(||LEVEL||) > [19]> then
stop all sounds
forever
play sound [ v] until done
end
end
end
it will keep testing the statement until the variable is more than 19. On the last time it does the loop, it will activate the if <> then statement. it will not skip over it, it just won't do any other actions until it stops repeating. It is a more than block so it won't keep looping at all, like i just said it will do its last test as you reach level 20.
Last edited by lokarz368 (Nov. 25, 2017 03:31:04)
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
The second will never do anything. If it is less than 19, then it will skip over the code, if it is 19 or more then it will keep looping until the level is less than 19 (which will not happen).forever
if <(||LEVEL||) > [19]> then
stop all sounds
play sound [ v] until done
end
end
or of there are other sounds playing in the levelsrepeat until <(||LEVEL||) > [19]>
if <(||LEVEL||) > [19]> then
stop all sounds
forever
play sound [ v] until done
end
end
end
it will keep testing the statement until the variable is more than 19. On the last time it does the loop, it will activate the if <> then statement
But when using a play sound until done, then the script doesn't check until the song is done. That is where a parallel loop can help as it can check and not be halted by the play until done block
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- lokarz368
- Scratcher
27 posts
Is There A Way To...?
The second will never do anything. If it is less than 19, then it will skip over the code, if it is 19 or more then it will keep looping until the level is less than 19 (which will not happen).forever
if <(||LEVEL||) > [19]> then
stop all sounds
play sound [ v] until done
end
end
or of there are other sounds playing in the levelsrepeat until <(||LEVEL||) > [19]>
if <(||LEVEL||) > [19]> then
stop all sounds
forever
play sound [ v] until done
end
end
end
it will keep testing the statement until the variable is more than 19. On the last time it does the loop, it will activate the if <> then statement
But when using a play sound until done, then the script doesn't check until the song is done. That is where a parallel loop can help as it can check and not be halted by the play until done block
No in one of my projects i have a play song until done in a forever block and it works fine. The sprite won't do any other actions until the sound is done. Also it will never stop all sounds as it is not in a forever block and its not repeating the if, then statement
Last edited by lokarz368 (Nov. 25, 2017 03:34:08)
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
Try this. It has a parallel loop that will run until the level is > 20, then it will stop all sounds, which will exit the first dance magic song and allow eggs to start right away.
https://scratch.mit.edu/projects/188645218/
https://scratch.mit.edu/projects/188645218/
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- PlantStar-Alpineer
- Scratcher
20 posts
Is There A Way To...?
Well, it only changes by 1 whenever you touch the goal.
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
Correct, so the level will change. I had to create a way for level to change automatically for the example as I don't have a game to show. So when you change the level variable after reaching the goal, the scripts I posted can be altered to fit that same scenario.
If you share your project we can have a more exact look to help
If you share your project we can have a more exact look to help
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- mstone326
- Scratcher
1000+ posts
Is There A Way To...?
Here is a remix. Check the backdrop and the exit sprite
https://scratch.mit.edu/projects/188647971/#player
https://scratch.mit.edu/projects/188647971/#player
High School Athletic Director / Middle School Tech Teacher / High School Baseball Coach
Kung Fu by Nintendo 1984 - https://scratch.mit.edu/projects/369994801/
Taco Defense - Speed Typing - https://scratch.mit.edu/projects/316795450/
Halloween Boss Battle - Taking Back our Woods - https://scratch.mit.edu/projects/257155118/
Almost Pong - https://scratch.mit.edu/projects/656276979/
Studio - My Best Projects - https://scratch.mit.edu/studios/4125978/
Forum Help Project Examples - https://scratch.mit.edu/studios/4133335
- Discussion Forums
- » Help with Scripts
- » Is There A Way To...?