Learning Goals 3 min
By the end of this lesson you will be able to:
- Find <> and <>, <> or <>, and not <> in the Operators palette and explain that all three take hexagonal inputs and report a hexagonal answer.
- Use and to require two things at once (e.g. "in the top-right quadrant" = x > 0 and y > 0) and or to accept either of two things.
- Use not to flip a yes/no answer — turning "touching edge" into "NOT touching edge" without having to invent a new sensor.
Warm-Up — two questions, one decision 7 min
Aljay's mum says he can have a slice of kuih lapis only if two things are true: he finished his homework and he washed his hands. Two questions. One decision. The kuih only appears when both answers are yes.
Imagine each question as a tiny hexagon in your head:
<homework done?>
<hands washed?>
How would you combine them so the kuih appears only when both are true?
Reveal the answer
You'd say "homework done and hands washed". The word and is itself a combiner — a tiny tool that takes two yes/no answers and reports one new yes/no answer. Both yes → yes. Anything else → no.
Scratch has the same tool, and it's a hexagon: <> and <>. Two diamond slots in, one diamond shape out.
Today's lesson is the three combinators that let you build complex questions out of simple ones — and, or, and not.
New Concept — the three combinators 15 min
In L02-09 you saw that every hexagonal block reports a yes-or-no answer. Today we meet three special hexagons that are different from all the others: they don't ask a question about the world. Instead, they take other hexagons as input and combine them into a new answer. They live in the green Operators palette, right under the comparison operators you met in L02-08.
And — both must be true
The <> and <> block has two diamond slots. It reports true only when both inputs are true. If either one is false, the whole thing is false.
<<(x position) > (0)> and <(y position) > (0)>>
Notice the double angle brackets — << ... and ... >>. The outer pair is the shape of the whole and-block. The inner pair belongs to each comparison. Two hexagons nested inside one bigger hexagon.
Or — at least one must be true
The <> or <> block also has two diamond slots. It reports true when either input is true (or both). It only reports false when both are false.
<<key [left arrow v] pressed?> or <key [a v] pressed?>>
Not — flip the answer
The not <> block has one diamond slot. It flips its input: true becomes false, false becomes true. It's how you ask the opposite of a question without having to invent a new sensor.
<not <touching [edge v] ?>>
The truth tables — small but important
Here are all the possible inputs and outputs for each combinator. There are only a few rows — boolean logic is small.
and (both must be true):
- true and true → true
- true and false → false
- false and true → false
- false and false → false
or (either one is enough):
- true or true → true
- true or false → true
- false or true → true
- false or false → false
not (flip it):
- not true → false
- not false → true
Combinators of combinators
Because each combinator reports a hexagon, you can drop a combinator into another combinator. Hexagons nest. This is how complex game logic gets built.
<<touching [edge v] ?> or <not <(score) > (0)>>>
Worked Example — the seeker's warm band 12 min
Back to Hot or Cold. Our seeker shouts HOT when very close and nothing useful in the middle. Today we add a warm band — the ring between 60 and 150 pixels — using an and hexagon. Open your saved project.
Step 1 — Open the project
Open Hot or Cold. Click the seeker. Find its forever loop with the distance tests.
Step 2 — Add an if-then for the band
From Control: if <> then. Drop it inside the forever, below the existing tests.
Step 3 — Grab the AND
From Operators: <> and <>. Drop it on the diamond. Two empty diamonds appear, left and right.
Step 4 — Left half: distance < 150
From Operators: () < () into the left diamond. From Sensing: distance to [treasure v] into its left slot. Type 150 on the right.
Step 5 — Right half: distance > 60
From Operators: () > () into the right diamond. From Sensing: another distance to [treasure v] on its left. Type 60 on the right.
Step 6 — The reaction
From Looks, inside the if-then C: say [Getting warmer] for (0.5) seconds.
Step 7 — The full warm-band stack
when flag clicked
forever
go to [mouse-pointer v]
if <(distance to [treasure v]) < (60)> then
say [HOT!] for (0.5) seconds
end
if <<(distance to [treasure v]) < (150)> and <(distance to [treasure v]) > (60)>> then
say [Getting warmer] for (0.5) seconds
end
end
Step 8 — Add "not found yet" with not
The not <> combinator flips an answer. We can announce "keep looking" while the seeker is not yet HOT:
if <not <(distance to [treasure v]) < (60)>> then
say [Not found yet...] for (0.5) seconds
end
Step 9 — Click the flag and hunt
Drag the seeker in slowly. Far away: "Not found yet". In the ring: "Getting warmer". Right on top: "HOT!". The band is alive.
What you just built: the same pattern that powers every region-detection feature in games — "are you in the safe zone?", "are you off the platform?". One and makes a band; one not flips a test. Next lesson we assemble the whole game and ship it.
Try It Yourself — three combinator drills 15 min
Goal: Make the cat say Move! for half a second when either the left arrow or the right arrow is pressed. Use <> or <>.
when flag clicked
forever
if <<key [left arrow v] pressed?> or <key [right arrow v] pressed?>> then
say [Move!] for (0.5) seconds
end
end
Think: If you used and here, the cat would only speak when you press both arrows at once — almost never. or is the right combinator when "any one of these is enough".
Goal: Use not <> to make the cat keep moving until it touches the edge. Inside a forever loop, only move (10) steps when the cat is not touching the edge.
when flag clicked
forever
if <not <touching [edge v] ?>> then
move (10) steps
end
end
Think: You could write this without not by using if <> then else, but the not-version reads more like English: "if I am NOT touching the edge, move". One block, one idea.
Goal: Combine all three combinators. The cat should say Safe! only when it is on the right half of the Stage (x > 0) AND it is NOT touching the edge OR the space key is pressed (a "panic button"). Think about the grouping carefully — Scratch evaluates whatever is inside the innermost hexagons first.
when flag clicked
forever
if <<<(x position) > (0)> and <not <touching [edge v] ?>>> or <key [space v] pressed?>> then
say [Safe!] for (0.5) seconds
end
end
Think: Read the brackets from the inside out. The and joins "right half" and "not touching edge". The or adds the space-key escape hatch. Three combinators, one big hexagon.
Mini-Challenge — the contradiction 5 min
"Aisyah's silent cat"
Aisyah wants the cat to say "Hi!" when it is in the top half of the Stage OR the bottom half of the Stage. She writes:
when flag clicked
forever
if <<(y position) > (0)> and <(y position) < (0)>> then
say [Hi!] for (0.5) seconds
end
end
Why is the cat silent? What's wrong with Aisyah's combinator, and how should she fix it?
Reveal one valid solution
Aisyah used and when she meant or. The and block needs both halves to be true at the same time — but a sprite cannot have y position both greater than 0 AND less than 0 simultaneously. The two conditions contradict each other, so and always reports false, so the if-then never fires.
What Aisyah actually meant — "top OR bottom" — is the or combinator:
when flag clicked
forever
if <<(y position) > (0)> or <(y position) < (0)>> then
say [Hi!] for (0.5) seconds
end
end
Now the cat says "Hi!" almost anywhere — the only place it stays silent is when y is exactly 0 (the dead centre line). Choosing the right combinator is half the work. When in doubt, read your sentence out loud in English: if you say "and", use and; if you say "or", use or.
Recap 3 min
You met the three combinator hexagons from the Operators palette. <> and <> takes two yes/no answers and reports true only when both are true. <> or <> reports true when at least one is true. not <> flips a single yes/no answer. Because all three are themselves hexagons, you can nest them inside each other to build complex game-logic questions out of simple sensor questions. Choosing between and and or is mostly an English problem — say your sentence out loud and the word you use is the block you need.
- Combinator
- A block that combines other blocks into a single answer. <> and <>, <> or <>, and not <> are the three boolean combinators in Scratch.
- And
- True only when both inputs are true. Otherwise false.
- Or
- True when at least one input is true. Only false when both are false.
- Not
- Flips its single input. True becomes false; false becomes true. The smallest combinator.
- Nesting
- Dropping one hexagon inside another. Because combinators report hexagons, they can be plugged into other combinators — building bigger questions out of smaller ones.
- Truth table
- A tiny chart showing every possible input and its output for a logic block. Useful for checking your own thinking when a combinator surprises you.
Homework 2 min
The Logic Gym. Build a single-sprite project that demonstrates all three combinators, one at a time.
- Drop a cat sprite. Add when ⚑ clicked and a forever.
- Inside the forever, add an if-then using <> and <> that combines two key presses (e.g. up arrow AND space). When both are true, say
And!. - Add a second if-then using <> or <> that fires when the left arrow OR the right arrow is pressed. Say
Or!. - Add a third if-then using not <> that fires when the cat is NOT touching the mouse pointer. Say
Not touching!— but only every couple of seconds (add a wait (2) seconds after the say so it doesn't spam). - Click the flag and try all three. Each combinator should fire under its own conditions.
Save as HW-L2-10-Logic-Gym.sb3.
Bring back next class:
- The
.sb3file. - Your answer to: "Make up a real-world rule from your life that uses BOTH and AND or. Write it as one English sentence (e.g. 'I can have dessert if I finished my vegetables AND it's not Monday, OR a guest is visiting.')."
Heads up for next class: SCR-L02-11 is the cluster-B capstone — a Hot or Cold hide-and-seek game that uses if/else-if chains, comparison operators, and the and/or logic you just learned. You'll put it all together into one playable game.