Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make on and off buttons?
- Gem-Studios
-
New Scratcher
2 posts
How do I make on and off buttons?
Hi! so I've been having a little trouble with something…
So I cant figure out how to make a functional on and off button. what I mean is this:
you can click the button and it makes the light turn on
and when you click it again it makes the light turn off. I know it may seem super simple but I'm kinda new to this. so can anyone help?
So I cant figure out how to make a functional on and off button. what I mean is this:
you can click the button and it makes the light turn on
and when you click it again it makes the light turn off. I know it may seem super simple but I'm kinda new to this. so can anyone help?
- nonethenones
-
Scratcher
100+ posts
How do I make on and off buttons?
when [m v] key pressed
switch costume to [light on v]
when [n v] key pressed
switch costume to [light off v]
Last edited by nonethenones (Jan. 28, 2017 22:07:17)
- Gem-Studios
-
New Scratcher
2 posts
How do I make on and off buttons?
Thank you!when [m v] key pressed
switch costume to [light on v]when [n v] key pressed
switch costume to [light off v]
- Toasty_Boy
-
Scratcher
100+ posts
How do I make on and off buttons?
Also in the two different button sprites you could add a
If this is to advanced then @nonethenones recommendation would be better.
when this sprite clickedand at the receiving sprite
broadcast [ On]
when I receive [ On]Same thing for the off button.
set [ On/Off] to [On]
If this is to advanced then @nonethenones recommendation would be better.
- woozybear62
-
Scratcher
1 post
How do I make on and off buttons?
EZ (easy) quick note: please be using scratch 2.0 version
when green flag clicked
switch costume to [ 2]
set [ v] to [0]
when this sprite clicked
if <[ v] = [0]> then
set [ v] to [1]
switch costume to [ 1]
stop [this script]
if <[ v] = [1]> then
set [ v] to [0]
switch costume to [2]
stop [this script]
end
Last edited by woozybear62 (June 24, 2017 22:39:53)
- footsocktoe
-
Scratcher
1000+ posts
How do I make on and off buttons?
Hi! so I've been having a little trouble with something…
So I cant figure out how to make a functional on and off button. what I mean is this:
you can click the button and it makes the light turn on
and when you click it again it makes the light turn off. I know it may seem super simple but I'm kinda new to this. so can anyone help?
Here is the easy way…
https://scratch.mit.edu/projects/155774332/
- Solmux
-
Scratcher
100+ posts
How do I make on and off buttons?
when this sprite clicked
change [ var v] by (1)
forever
if <(var) = [3]> then
set [ var v] to [1]
end
end
Next…
when green flag clicked
set [ var v] to [1]
forever
if <(var) = [1]> then
this is off
else
if <(var) = [2]> then
this is on
end
end
idk if this works but try
- clego
-
Scratcher
16 posts
How do I make on and off buttons?
I believe you are talking about a toggle on and off button:
when green flag clicked
forever
if <(Variable) = [0]> then
move (10) steps
end
if <(Variable) = [1]> then
move (-10) steps
end
if <(Variable) = [2]> then
set [Variable] to [0]
end
end
when this sprite clicked
change [Variable] by (1)
when green flag clicked
set [Variable] to [0]
- asivi
-
Scratcher
1000+ posts
How do I make on and off buttons?
Hi! so I've been having a little trouble with something…
So I cant figure out how to make a functional on and off button. what I mean is this:
you can click the button and it makes the light turn on
and when you click it again it makes the light turn off. I know it may seem super simple but I'm kinda new to this. so can anyone help?
Here is the easy way…
https://scratch.mit.edu/projects/155774332/
^^^ good ^^^
- Paigeri
-
Scratcher
500+ posts
How do I make on and off buttons?
Since you have figured this out, I would suggest this to be closed so the forums can be a little bit more organized 

- awesomellama08
-
Scratcher
11 posts
How do I make on and off buttons?
Hi, I think I know so first you do this stuff
when green flag clicked
set [ on/off] to [true]
switch costume to [ costume 2]
(or false)
Then you do this,
[scratchblocks]
when [ v] key pressed
[/scratchblocks] [scratchblocks]
if <[0n/off] = [true]> then
switch costume to [ 1]
set [ on/off] to [false]
else
set [ on/off] to [true]
switch costume to [ 2]
end
[/scratchblocks]
- Discussion Forums
- » Help with Scripts
-
» How do I make on and off buttons?
