Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a toggle on/off script with only one button
- Thelnvoker
-
Scratcher
100+ posts
How to make a toggle on/off script with only one button
So I'm making a test project, in which the sprite starts off showing, but when the space key is pressed, the sprite hides. If the space key is pressed again, it shows. I set up a variable to test this, but it won't work. Can someone tell me what I'm doing wrong?
This script above may have mistakes that are different from the actual script, so if you need me to clarify, let me know.
when green flag clicked
set [Look ] to [showing ]
forever
if (<[Look] = [showing ]>) then
show
if (<[Look] = [hiding ]>) then
hide
if <key [space] pressed?> then
if (<[Look] = [showing ]>) then
hide
if (<[Look] = [hiding ]>) then
hide
end
end
end
end
end
end
This script above may have mistakes that are different from the actual script, so if you need me to clarify, let me know.
Last edited by Thelnvoker (Feb. 14, 2016 04:31:31)
- crisostimo
-
Scratcher
500+ posts
How to make a toggle on/off script with only one button
Always glad to see someone trying out programming.
Oh, how I wish they never had included ‘forever’ in Scratch (bit of a theme for me in forum posts). It's almost always the wrong approach and seems so tempting at first.
Oh, how I wish they never had included ‘forever’ in Scratch (bit of a theme for me in forum posts). It's almost always the wrong approach and seems so tempting at first.
when gf clicked
set [Is Visible v] to [true]
show
when [space v] key pressed
if <(Is Visible) = [true]> then
set [Is Visible v] to [false]
hide
else
set [Is Visible v] to [true]
show
end
- Thelnvoker
-
Scratcher
100+ posts
How to make a toggle on/off script with only one button
Thanks so much!
I will try it out as soon as I can!
I will try it out as soon as I can!- SomeRandomStickboy
-
Scratcher
23 posts
How to make a toggle on/off script with only one button
This did not work for me when trying to make a volume toggle.
- duckboycool
-
Scratcher
1000+ posts
How to make a toggle on/off script with only one button
This did not work for me when trying to make a volume toggle.Hello, please check the dates of topics and recent posts before posting on them. In the future you should make new topics instead of posing on old ones. Thank you.
For making a volume toggle you could have two sprites (An addition sign and a subtraction sign) and have them use;
when this sprite clicked
change volume by ()//increasing or decreasing depending on button
- Thelnvoker
-
Scratcher
100+ posts
How to make a toggle on/off script with only one button
Lol this was made like at least half a year ago, I should close this topic anyways 

- Discussion Forums
- » Help with Scripts
-
» How to make a toggle on/off script with only one button