| Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (August 2021) |
Toggles are used to turn sound off and on, control a sprite, and more. This tutorial will list two methods on how to make a toggle.
Method 1
This method uses the when this sprite clicked hat block to sense if the sprite is clicked. This one needs two costumes, one when the switch is on, and one when the switch is off.
when gf clicked
set [toggle v] to [off]
when this sprite clicked
if <(toggle) = [off]> then
set [toggle v] to [on]
switch costume to (on v)
else
set [toggle v] to [off]
switch costume to (off v)
end
Method 2
The same effect can be achieved with this script, using numerical values and operations to toggle between 0 (being off) and 1 (being on):
when gf clicked
set [toggle v] to [0]
when [space v] key pressed
set [toggle v] to ((1) - (toggle))
if <(toggle) = [1]> then
. . . // toggle is on
else
. . . // toggle is off
end