Discuss Scratch

RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

I'm having so much trouble coding a pause button. Can someone help me?

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

What in specific do you need to pause? IE, dialogue, a cutscene, enemy AI and player movement, etc

this is my signature
I have exactly 8934 posts
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

@25Freyst I think i want to pause player movement like arrow keys and stuff and glide 1 seconds to

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
lion334
Scratcher
100+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

RyRy33096 wrote:

I'm having so much trouble coding a pause button. Can someone help me?
Hi…
So first of all, coding a Paus Button is really really hard, but I think I have some solutions, ranging from simple to hard but effective.
1) Don't reset Variables on Play, this ain't that effective in most games tho. However, for like super simple games it can be effective as you cna just stop the game and restart it.
2) turbowarp. If you want to play / code your Project, use TurboWarp, as it has a Pause Button. However, this PauseButton isnt ingame, it is from Turbowarp.
3) Make a Variable called “Pause”. after this, add this to literally anywhere in your code:
wait until <(pause) = [0]>
Then, if you want to pause, use something like this:
when this sprite clicked
if <[(pause)] = [0]> then
set [pause] to [1]
else
set [pause] to [0]
end

This is complicated as hell, but quite effective.

Hi, I'm Mirau or lion334

Made some cool game a while ago: You're not gonna click it though… right?


GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

Make a new variable, paused, for the player sprite. Add a key hat block(or custom block, they’re what this is based off)

when [P v] key pressed        (Can be replaced)
if <(Paused) = [1]> then
set [Paused v] to [0]
else
set [Paused v] to [1]
end
Than, for the players movement script, check of paused = 1.
Edit: Beaten by a minute.
Edit 2: Rather than a wait button, depending on your setup, I’d suggest an if than block. A wait block, to my knowledge, waits for it to be true, and may offset they players movement if they paused depending on how your code is. If its:
if <touching [X v] ?> then
wait until <[(Paused?)] = [0]>
say [Hello World!] for (2) secs
end
It may cause problems, if its
forever
wait until <[(Paused)] = [0]>
Script here
end
It won’t be affected much.

Last edited by GIitchInTheMatrix (April 4, 2022 15:38:15)


this is my signature
I have exactly 8934 posts
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

25Freyst wrote:

Make a new variable, paused, for the player sprite. Add a key hat block(or custom block, they’re what this is based off)

when [P v] key pressed        (Can be replaced)
if <(Paused) = [1]> then
set [Paused v] to [0]
else
set [Paused v] to [1]
end
Than, for the players movement script, check of paused = 1.
Edit: Beaten by a minute.

what

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

RyRy33096 wrote:

25Freyst wrote:

Make a new variable, paused, for the player sprite. Add a key hat block(or custom block, they’re what this is based off)

when [P v] key pressed        (Can be replaced)
if <(Paused) = [1]> then
set [Paused v] to [0]
else
set [Paused v] to [1]
end
Than, for the players movement script, check of paused = 1.
Edit: Beaten by a minute.

what
Beaten is due to the other post.
The red block is supposed to be a
when [P v] key pressed
Saying it can be changed, but Scratch forums blocks work a little differently than I expected.

this is my signature
I have exactly 8934 posts
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

i did this is it good
when green flag clicked
set [(paused?)] to [no]
hide
wait (4) secs
forever
if <key [p] pressed?> then
set [(paused?)] to [yes]
end
if <(paused?) = [yes]> then

wait until <not <key [p] pressed?>>

else
wait until <touching [p] ?>
end
end

Last edited by RyRy33096 (April 4, 2022 15:46:18)


when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

RyRy33096 wrote:

i did this is it good
when green flag clicked
set [paused?] to [no]
hide
wait (4) secs
forever
if <key [p] pressed?> then
set [paused?] to [yes]
end
if <(paused?) = [yes]> then

wait until <not <key [p] pressed?>>

else
wait until <touching [p] ?>
end
end
now how do pause the sprites?

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

Under the sprites scripts(the ones that need pausing), add in an if than block. Check if the pause variable is no, if so, run the code.

this is my signature
I have exactly 8934 posts
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

25Freyst wrote:

Under the sprites scripts(the ones that need pausing), add in an if than block. Check if the pause variable is no, if so, run the code.
can you explain what you mean

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

forever
if <(Pause) = [False]> then
Your code here
end
end

this is my signature
I have exactly 8934 posts
Triton2009
Scratcher
24 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

This is my way to code a pause button. When you start working on your pause button, make sure to replace the
when green flag clicked
blocks with
when I receive [message1 v]
, except several blocks that set the position, size, and effect (those can stay within the green flag scripts), otherwise there will be bugs later on. Then on your pause menu button sprite, do
when green flag clicked
broadcast [message1 v]
For the pause button to show and hide the pause menu, create one variable named “pause ghost (make sure this variable is for every sprite)” then add a set () to () block in the Variables category. Add this block in the “when green flag clicked” script, so your code should look like this:
when green flag clicked
set [pause ghost v] to [100] // Make sure you set "pause ghost" to 100, so the pause menu is hidden, but it is still visible to all sprites.
broadcast [message1 v]
and then use this code to trigger the pause menu on and off:
when this sprite clicked
set [pause ghost v] to ([100] - (pause ghost))
broadcast [Toggle Pause Menu v]
(The “() - ()” block, found in the Operators category, can be used to toggle between 100 and 0, or the addition and mod blocks can be used too. It doesn't matter which Operators blocks you should use. For addition, it doesn't matter which order you should use. Using both orders with the same numbers should get you the same answer. The mod block always returns an answer of 200 back to 0, toggling the pause menu on or off.) These blocks can be used:
(([100] + (pause ghost)) mod [200])
or if you are using key presses to trigger the pause menu, you should do this code:
when [p v] key pressed // Put whatever key you want there. For example, I'm using the p key to trigger the pause menu.
set [pause ghost v] to ([100] - (pause ghost))
broadcast [Toggle Pause Menu v]
, and use this when I receive () block to stop the scripts that are going on if the pause ghost variable is set to 0.
when I receive [Toggle Pause Menu v] // Put this code in every sprite (except for the pause button) one and the stage.
if <(pause ghost) = [0]> then
stop [other scripts in sprite v]
end
Create a new sprite named “pause menu.” You can customize it all you want, but use this code for it:
when green flag clicked
set [ghost v] effect to [100]

when I receive [Toggle Pause Menu v]
set [ghost v] effect to (pause ghost)
if <(pause ghost) = [100]> then
broadcast [message1 v]
end

Last edited by Triton2009 (April 4, 2022 20:04:14)


when [timer v] > [-1]
forever
if <everyone else is already taken :: sensing> then
be yourself :: custom
end
end
“Be yourself, everyone else is already taken”
- Oscar Wilde
Check this project out before the evil kumquats eat your siggy! Hurry!
Last edited by kaj Tomorrow 00:00:00
sadiqnafees
Scratcher
22 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

RyRy33096 wrote:

@25Freyst I think i want to pause player movement like arrow keys and stuff and glide 1 seconds to
press quote to reply
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

Triton2009 wrote:

This is my way to code a pause button. When you start working on your pause button, make sure to replace the
when green flag clicked
blocks with
when I receive [message1 v]
, except several blocks that set the position, size, and effect (those can stay within the green flag scripts), otherwise there will be bugs later on. Then on your pause menu button sprite, do
when green flag clicked
broadcast [message1 v]
For the pause button to show and hide the pause menu, create one variable named “pause ghost (make sure this variable is for every sprite)” then add a set () to () block in the Variables category. Add this block in the “when green flag clicked” script, so your code should look like this:
when green flag clicked
set [pause ghost v] to [100] // Make sure you set "pause ghost" to 100, so the pause menu is hidden, but it is still visible to all sprites.
broadcast [message1 v]
and then use this code to trigger the pause menu on and off:
when this sprite clicked
set [pause ghost v] to ([100] - (pause ghost))
broadcast [Toggle Pause Menu v]
(The “() - ()” block, found in the Operators category, can be used to toggle between 100 and 0, or the addition and mod blocks can be used too. It doesn't matter which Operators blocks you should use. For addition, it doesn't matter which order you should use. Using both orders with the same numbers should get you the same answer. The mod block always returns an answer of 200 back to 0, toggling the pause menu on or off.) These blocks can be used:
(([100] + (pause ghost)) mod [200])
or if you are using key presses to trigger the pause menu, you should do this code:
when [p v] key pressed // Put whatever key you want there. For example, I'm using the p key to trigger the pause menu.
set [pause ghost v] to ([100] - (pause ghost))
broadcast [Toggle Pause Menu v]
, and use this when I receive () block to stop the scripts that are going on if the pause ghost variable is set to 0.
when I receive [Toggle Pause Menu v] // Put this code in every sprite (except for the pause button) one and the stage.
if <(pause ghost) = [0]> then
stop [other scripts in sprite v]
end
Create a new sprite named “pause menu.” You can customize it all you want, but use this code for it:
when green flag clicked
set [ghost v] effect to [100]

when I receive [Toggle Pause Menu v]
set [ghost v] effect to (pause ghost)
if <(pause ghost) = [100]> then
broadcast [message1 v]
end
how do i make my signature

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
GIitchInTheMatrix
Scratcher
1000+ posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

RyRy33096 wrote:

Triton2009 wrote:

An answer
how do i make my signature
Go to discussion home, and scroll to the bottom of the page. Theres an option that says ‘change your signature.’ Press it and make one. Press submit and it’ll appear under all of your posts.

this is my signature
I have exactly 8934 posts
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

thank you you can see my signature

25Freyst wrote:

RyRy33096 wrote:

Triton2009 wrote:

An answer
how do i make my signature
Go to discussion home, and scroll to the bottom of the page. Theres an option that says ‘change your signature.’ Press it and make one. Press submit and it’ll appear under all of your posts.

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol
build100
Scratcher
36 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

If you mean pause a sound than you could do this.
when [p] key pressed
if <(paused?) = [1]> then
set [paused] to [0]
set [pitch] effect to ((-1) / (0))

else
set [paused] to [1]
set [pitch] effect to [0]
end

The pitch effect actually is the speed so we can set it -inf (-1/0 in our case) and it will pause. Then we can set it back and it will appear as if we paused the music.

Last edited by build100 (April 5, 2022 22:58:01)


when [view my project v]
like (currant project)
favorite (currant project)
add (username) to [followers v]
YNKAL
New to Scratch
31 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

I mean you could make a variable called pause? and either make is 0 or 1 and for other scirpts do this
when green flag clicked
forever
if <[pause] = [0]> then
the script
end
end

I'm always bored
RyRy33096
Scratcher
25 posts

h o w t o c o d e a p a u s e b u t t o n ? ? ?

ty everyone I got it but it only works once when I finish my projecc ill share and post it here

when green flag clicked
if <<(you) = [go to my profile]> and <(you) = [like hard space games that are epic]>> then
forever
play my epic games
end


else
play my other epic games
broadcast [lol its too good v]
end
create clone of [people v]
repeat the blocks above me
stop [this epic script v]

when I receive [lol its too good v]
repeat [INFINITY]
to play all of my games and follow me
create clone of [my epic viewers v]
end
broadcast [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
stop [this epic script v]

when I receive [more people are playing my projects and I'm getting famous and griffpatch followed me :O v]
say [happy ryry] for [epic] secs

when [tick v] > (-1)
recommend the game [TPS v] link: [https://scratch.mit.edu/projects/668408387/ v]
mouse go [highlight the url right click it click go to https://scratch.mit.edu/projects/668408387/ v]

when green flag clicked
say [You have choice :0] for [2] secs
follow?{(yos :D)}{(lol no D:)}{(you lookin kinda sus ngl)}
talk (tell me whats ur answer by following me :})

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{({({})})}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
the void lol

Powered by DjangoBB