Discuss Scratch

snakeboy712
Scratcher
100+ posts

How do i make a sprite disappear and re-appear when a key is pressed

How do i make something that disappears when you press a key and then re-appears when you press
the same key again?
jokebookservice1
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

First, let's make a variable that remembers if you have pressed the key. Let's call it
hasPressedKey
Now, let's pretend it is the space bar you are after:
whenclickedsethasPressedKeytoNowhenspacekeypressedifhasPressedKey=YesthensethasPressedKeytoNoshowelsesethasPressedKeytoYeshide
snakeboy712
Scratcher
100+ posts

How do i make a sprite disappear and re-appear when a key is pressed

Time to see if the script worked…


Apparently not i don't know why…
asivi
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

jokebookservice1 wrote:

First, let's make a variable that remembers if you have pressed the key. Let's call it
hasPressedKey
Now, let's pretend it is the space bar you are after:
whenclickedsethasPressedKeytoNowhenspacekeypressedifhasPressedKey=YesthensethasPressedKeytoNoshowelsesethasPressedKeytoYeshide
@jokebookservice1 is right but better if you add at the end of that script
waituntilnotkeyspacepressed?
jokebookservice1
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

asivi wrote:

jokebookservice1 wrote:

First, let's make a variable that remembers if you have pressed the key. Let's call it
hasPressedKey
Now, let's pretend it is the space bar you are after:
whenclickedsethasPressedKeytoNowhenspacekeypressedifhasPressedKey=YesthensethasPressedKeytoNoshowelsesethasPressedKeytoYeshide
@jokebookservice1 is right but better if you add at the end of that script
waituntilnotkeyspacepressed?
Why? (I wasn't using a forever loop)
Also, are you sure it doesn't work, here is a link: https://scratch.mit.edu/projects/108622169/
_TigerJack21_
Scratcher
83 posts

How do i make a sprite disappear and re-appear when a key is pressed

jokebookservice1 wrote:

asivi wrote:

jokebookservice1 wrote:

First, let's make a variable that remembers if you have pressed the key. Let's call it
hasPressedKey
Now, let's pretend it is the space bar you are after:
whenclickedsethasPressedKeytoNowhenspacekeypressedifhasPressedKey=YesthensethasPressedKeytoNoshowelsesethasPressedKeytoYeshide
@jokebookservice1 is right but better if you add at the end of that script
waituntilnotkeyspacepressed?
Why? (I wasn't using a forever loop)
Also, are you sure it doesn't work, here is a link: https://scratch.mit.edu/projects/108622169/
No, I think asivi is correct. Because you haven't added a delay, the “when space key pressed” block will be activated multiple times. This is bad because the results will be very unpredictable.

Last edited by _TigerJack21_ (May 7, 2016 10:51:13)

asivi
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

jokebookservice1 wrote:

asivi wrote:

jokebookservice1 wrote:

First, let's make a variable that remembers if you have pressed the key. Let's call it
hasPressedKey
Now, let's pretend it is the space bar you are after:
whenclickedsethasPressedKeytoNowhenspacekeypressedifhasPressedKey=YesthensethasPressedKeytoNoshowelsesethasPressedKeytoYeshide
@jokebookservice1 is right but better if you add at the end of that script
waituntilnotkeyspacepressed?
Why? (I wasn't using a forever loop)
Also, are you sure it doesn't work, here is a link: https://scratch.mit.edu/projects/108622169/
It is for prevent more than once key detection if the user press the key for a while.
jokebookservice1
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

Ok
snakeboy712
Scratcher
100+ posts

How do i make a sprite disappear and re-appear when a key is pressed

Nevermind it works now
asivi
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

Of course, never was a trouble.
78sowens
Scratcher
2 posts

How do i make a sprite disappear and re-appear when a key is pressed

showhide
-frostyiceprincess-
Scratcher
1000+ posts

How do i make a sprite disappear and re-appear when a key is pressed

78sowens wrote:

showhide
Please don't necropost.
PhoenixDragonBlue
Scratcher
100+ posts

How do i make a sprite disappear and re-appear when a key is pressed

78sowens wrote:

showhide
Please don't necro-post (bump an old topic). Also, please do not post on a topic in the “Help with Scripts” with the problem already solved (in fact, I'm not sure why this isn't closed).
ebonysp
New Scratcher
1 post

How do i make a sprite disappear and re-appear when a key is pressed

Hey gorls is gengal gengal
Thefrenchpeople
Scratcher
500+ posts

How do i make a sprite disappear and re-appear when a key is pressed

ebonysp wrote:

Hey gorls is gengal gengal
Please don't necropost. This topic is from 2017.
Codicar
Scratcher
8 posts

How do i make a sprite disappear and re-appear when a key is pressed

Hey dudes shut up, lol
this is not the dumb script he/she is talking about
Guest_102233
Scratcher
100+ posts

How do i make a sprite disappear and re-appear when a key is pressed

Codicar wrote:

Hey dudes shut up, lol
this is not the dumb script he/she is talking about
Please refrain from necroposting on a topic resolved more than 4 years ago. This will make the topic seem it is new. I don't know why it hasn't been closed yet.

Powered by DjangoBB