Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do i make an on and off switch
- SeanRed111
-
7 posts
How do i make an on and off switch
i would like to make an on and off switch that when clicked changes a variable and when clicked another time changes it back.
- mstone326
-
1000+ posts
How do i make an on and off switch
You have the right idea. Use a variable to track the current state. Here is an example.
Last edited by mstone326 (May 25, 2018 23:11:32)
- SeanRed111
-
7 posts
How do i make an on and off switch
You have the right idea. Use a variable to track the current state. Here is an example.
how do i get the red blocks?
- mstone326
-
1000+ posts
How do i make an on and off switch
The red blocks are just for the forum. I put them where you would put what should happen when the light goes on and when the light goes off. Maybe you have a costume with the light on, and a costume with a light off. See if this project helps
https://scratch.mit.edu/projects/194036878/#editor
https://scratch.mit.edu/projects/194036878/#editor
Last edited by mstone326 (May 25, 2018 23:38:12)
- SeanRed111
-
7 posts
How do i make an on and off switch
The red blocks are just for the forum. I put them where you would put what should happen when the light goes on and when the light goes off. Maybe you have a costume with the light on, and a costume with a light off. See if this project helps
https://scratch.mit.edu/projects/194036878/#editor
i tired the script but when i click the sprite it changes the variable but will not change it back
where you put the red blocks i set it to change a variable to 0 then 1 but when it changes to 1 it will not go back if i click it again
- mstone326
-
1000+ posts
How do i make an on and off switch
Did you look at the project I shared?
If not, look at that. Also, share the project you need help with and we can look and help you along.
If not, look at that. Also, share the project you need help with and we can look and help you along.
- SeanRed111
-
7 posts
How do i make an on and off switch
thank you it worked, what went wrong is that i used the wrong variable in the script. well thank you
- mstone326
-
1000+ posts
How do i make an on and off switch
Welcome to Scratch. Best of luck on your project!
- OTSFan203
-
500+ posts
How do i make an on and off switch
make a sprite for switch, and write this script:
Last edited by OTSFan203 (May 26, 2018 14:14:02)
- deck26
-
1000+ posts
How do i make an on and off switch
Both scripts will run when the sprite is clicked but even if you're controlling the order you'll have a problem. Imagine they run in the order shown and light=off. It'll gets switched to on in the first script and then off again in the second. If it's on it'll get switched off by the second. make a sprite for switch, and write this script:
Change the order ofthe scripts and you get the opposite problem - it will always end up on.
- MeIzAwezomeDede
-
1000+ posts
How do i make an on and off switch
That wouldn't really work… and this post in 2 years old. when green flag clicked
You're a new user so you're OK, but please pay attention to when things have been published next time

- Harakou
-
1000+ posts
How do i make an on and off switch
That's great! However, please don't post on old questions like this - it bumps them back to the top of the index, which is confusing for others. This was helpful, thanks!

- Discussion Forums
- » Help with Scripts
-
» How do i make an on and off switch