Discuss Scratch

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?
nonethenones
Scratcher
100+ posts

How do I make on and off buttons?

whenmkeypressedswitchcostumetolight on

whennkeypressedswitchcostumetolight off

Last edited by nonethenones (Jan. 28, 2017 22:07:17)

Gem-Studios
New Scratcher
2 posts

How do I make on and off buttons?

nonethenones wrote:

whenmkeypressedswitchcostumetolight on

whennkeypressedswitchcostumetolight off
Thank you!
Toasty_Boy
Scratcher
100+ posts

How do I make on and off buttons?

Also in the two different button sprites you could add a
whenthisspriteclickedbroadcast On
and at the receiving sprite
whenIreceive Onset On/OfftoOn
Same thing for the off button.
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

whenclickedswitchcostumeto 2setto0

whenthisspriteclickedif=0thensetto1switchcostumeto 1stopthis scriptif=1thensetto0switchcostumeto2stopthis script

Last edited by woozybear62 (June 24, 2017 22:39:53)

footsocktoe
Scratcher
1000+ posts

How do I make on and off buttons?

Gem-Studios wrote:

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?

whenthisspriteclickedchange varby1foreverifvar=3thenset varto1

Next…

whenclickedset varto1foreverifvar=1thenthisisoffelseifvar=2thenthisison

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:
whenclickedforeverifVariable=0thenmove10stepsifVariable=1thenmove-10stepsifVariable=2thensetVariableto0whenthisspriteclickedchangeVariableby1whenclickedsetVariableto0
asivi
Scratcher
1000+ posts

How do I make on and off buttons?

footsocktoe wrote:

Gem-Studios wrote:

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 ^^^
Ilhan_Squla
Scratcher
4 posts

How do I make on and off buttons?

show
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
Chicken_Geek_2
Scratcher
11 posts

How do I make on and off buttons?

awesomellama08
Scratcher
11 posts

How do I make on and off buttons?

Hi, I think I know so first you do this stuff

whenclicked
set on/offtotrue
switchcostumeto costume 2orfalseThenyoudothis,scratchblockswhenkeypressed/scratchblocksscratchblocksif0n/off=truethenswitchcostumeto 1set on/offtofalseelseset on/offtotrueswitchcostumeto 2/scratchblocks

Powered by DjangoBB