From Test-Scratch-Wiki

Revision as of 18:58, 12 June 2016 by InterwikiBot (talk | contribs) (Uploading Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Translate: - English - Español - Türkçe - 한국어 
The general shape of a Boolean block.
A Boolean block is a hexagonal block (shaped after the Boolean elements in flowcharts) that contains a condition. When this block is invoked, it acts as a Reporter Block, reporting true or false.

There are 13 Boolean blocks, and they can be found in the Sensing, Operators and Variables categories. Custom blocks can have boolean inputs that may be present in a block definition.


There are 13 Boolean blocks in Scratch 2.0, as follows:


Boolean blocks are conditions that can either be true or false. They have a hexagonal shape and fit in the corresponding hexagonal slot on other blocks.

The condition gap can be filled with any Boolean block:

if <key [space v] pressed?> then
broadcast [Jump! v]

Despite their shapes, Boolean blocks also fit in string inputs:

when gf clicked
say <touching [Sprite1 v]?>

and also number ones!

when gf clicked
  say ((0) + <touching [Sprite1 v]?>)

They still report true or false, but in the example, the sprite will interpret this as a string and just say the word.

In the Blocks Plugin, these blocks appear the same as reporters, due to a technical limitation of CSS. See bug #2.


Scratch has two types of Booleans: Booleans that check a specific condition, and comparative Booleans.

Conditional Booleans check a specific condition. Examples include the () Contains () and Touching ()? blocks.

Comparative Booleans compare values. These include () = (), () and (), and Not (). For some of these, a truth table will predict their return values.


As Boolean blocks are conditions (and report if they are true or false), they are used whenever a condition is needed. Conditions are used with some C blocks and some Control Stack blocks. A common use for conditions is the If () Then block — if the condition is true, the blocks held inside the C block will activate.

There are a variety of different conditions that can be checked, from checking if the mouse is touching a sprite to checking if a value is equal to another value. An example is below:

when flag clicked
repeat until <(do_Stop) = [1]>
  move (10) steps
  change [color v] effect by (25)
  play sound [meow v] until done
  if <touching [edge v]?> then
    say [Done!] for (2) secs
    stop [this script v]

Note how the Boolean block () = () is being used to check if the Variable Stop is equal to 1. If the condition is false (wrong or not true), then the blocks held inside the If () Then block will run.

Other Uses

Direct Comparison

Boolean variables can be compared to non-boolean variables. For example, the following script, two booleans are compared to each other directly, and the if statement will execute the code inside if both have the same value (i.e. both true or both false).

if <<mouse down> = <touching color [#00A]>>

Storage in Variables

Booleans can be stored in variables as well. The following script stores the current mouse state in the variable "bool".

set [bool v] to <mouse down?>

Later, the variable can be compared to another boolean with the stored variable:

if (<mouse down?> = (bool))

In this case, the script will check whether the mouse currently has the same state as it did when the variable was stored.

External Links

See Also