How to Make a Toggle

Материал из Поле цифровой дидактики

Шаблон:Expand 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, both of an on and off switch.

...settoggletooffwhenthisspriteclickediftoggle=offthensettoggletoonswitchcostumetoonelsesettoggletooffswitchcostumetooffend

Method 2

The same effect can be achieved with this script, using numerical values and logical operations to toggle between 0 (being off) and 1 (being on):

whenclickedsettoggleto0whenspacekeypressedsettoggletotoggle=0iftoggle=1then...toggleisonelse...toggleisoffend