Hardware Reference
In-Depth Information
Figure 10-9:
Controlling the
Cheesy-Pufs
with a Scratch
if block
Boolean Logic
Named for George Boole, Boolean logic or Boolean algebra is a key concept to understand-
ing how computers work. In Scratch, Boolean logic is implemented in three Operators
bricks:
and
,
or
and
not
.
The
and
operator requires that two inputs—in Scratch's case, Sensing blocks—are both
true before its own output will be true. If neither of its inputs is true, or if both inputs are
false, its own output will be false. You can use this operator to check to see if a sprite is
touching two other sprites, as an example.
The
or
operator requires that one or the other of its two inputs are true. If either input is
true, the operator's output will also be true. This is a handy way of re-using code: if you have
multiple sprites that are lethal to the player sprite, a single block of code can be used with
the
or
operator to trigger when any of the enemy sprites are touched.
Finally, the
not
operator is known as an
inverter
: whatever its single input is, it outputs the
opposite. If its input is false, then the output is true; if the input is true, then the output is false.