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)
I'm a basically a potato or cat or something with a very dark sense of humor who likes steampunk, traditional art, Skyrim, etc.
Anyone wanna RP with me?
- 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
Enjoy puzzle games? Play or See Inside -
Instruction Set
Almost Alchemy
Pyramid Solitaire
Number Slider
Scratch Assembler (Beta)
- 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'm a basically a potato or cat or something with a very dark sense of humor who likes steampunk, traditional art, Skyrim, etc.
Anyone wanna RP with me?
- 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.
“The two most important days in your life are the day you were born, and the day you find out why.”
-Mark Twain
People: Violence is not the answer!
Me: *Slaps them in the face with a history book on the last 40,000 years titled “Read me!”
- duckboycool
- Scratcher
1000+ posts
How to make a toggle on/off script with only one button
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. This did not work for me when trying to make a volume toggle.
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
I used to be active on the forums, but I have mostly moved past Scratch. I still do check my Scratch messages, so if you'd like to talk to me, just leave a comment on my profile. My main project on Scratch was Cookie Clicker, but my newest project is Snake Snake, a game based off of Snake, but with two snakes, and you can play either singleplayer or multiplayer.
- 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
I'm a basically a potato or cat or something with a very dark sense of humor who likes steampunk, traditional art, Skyrim, etc.
Anyone wanna RP with me?
- Discussion Forums
- » Help with Scripts
- » How to make a toggle on/off script with only one button