In MakeCode, there are lots of bright colours, and funky block shapes.
They aren’t just for looks – the colour and shape of a block tells you a lot about it.
PITSTOP: TOP TIPS #1!
You can right-click on any block in the editor and click on ‘Help‘ (try it) to bring up an explanation of how that block works.
Colours are Categories
On the left side of the editor window are several coloured categories – each one holds similar blocks.
Click on a category to open it. (You can also use the ‘search’ function if you remember the name of a block but not where to find it)
If a block in the window is grey, that means it’s inactive – it won’t be included in your program.
Each of the categories has a help page; look through them to learn more.
Shapes have Meaning
MakeCode is a little bit like a Lego kit; blocks snap into each other in many many ways.
If you try to put a block where it doesn’t belong, the editor will stop you.
(or the block will stay grey and disconnected)
There are only FOUR basic shapes:
- A Statement is one step / one instruction / one action. It means “Do this.”
- Statements can be snapped together into a list.
- A list of Statements is run; in order, one after the other, from top to bottom.
- Statements have to live inside a Container.
(If placed anywhere else, the Statement will be disabled and greyed out)
- A Container holds statements inside it.
Containers can stretch to hold any number of statements, or even be empty.
- A Container lets you choose when to run those statements.
forevercontainer block runs the statements inside it over and over again.
on Shakecontainer block runs the statements inside it once each time the board is shaken.
- Some Container blocks have puzzle-piece-marks on the outside too.
These blocks are both a Container and a Statement;
- They hold any number of statements inside, but
- They have to live inside another container.
ifcontainer block runs the statements inside it only if the boolean condition at the top is true.
- An expression is a block or set of blocks that represent a value.
(Usually a number, but there are other types)
- These expressions are passed into other blocks to control them,
eg: in this
repeatblock, the expression
4controls how many times the ‘jump up’ sound plays.
- Expressions have a lot of power and flexibility.
- The Math category lets you build and combine many kinds of expression, like a mathematical equation.
- The Variables category (which we’ll learn more about later) lets us store information in memory and build complex behaviour.
- Every other category has expressions too; the Input category has
sound level, Music has
tempo (bpm), etc.
- A Boolean is one of two possible values;
- Logical blocks like
notcombine inputs in a Boolean way and make another Boolean value:
eg: the ‘shouldIMisbehave‘ variable will be set to
trueif ‘isBored‘ is
trueand ‘teacherIsLooking’ is
false, otherwise it will be
isBored teacherIsLooking shouldIMisbehave
- Comparison blocks like
≤let you compare values numerically, and make a Boolean value:
≥comparison block above will be set to
trueif ‘dice_roll’ is 5 or higher, otherwise it will be
dice_roll dice_roll ≥ 5 3
- Booleans are often used to control Containers like
while– to control whether the program should run steps inside them, and if so how many times.
There are only four basic kinds of block, but like Lego there are many many ways they can go together.
Figuring out the best way to accomplish something takes practice – nobody is an expert overnight.
For each of the blocks below, are they a Statement, a Container, an Expression or a Boolean?
Write the answers in your worksheet.
|On Shake Block|
|Show Ring Block|
|On Start Block|
|Pick Random Block|
|Play Tone Block|
|Set Light Block|
|Was Pressed Block|