Skip to main content

Booleans

note

Anything that only works unsandboxed will be noted, but regardless, we will assume you are creating an unsandboxed extension during this tutorial.

Make a new block

Add a new object to the blocks array. This time, the blockType should be Scratch.BlockType.BOOLEAN.

Let's spice it up a bit. This block will use Math.random() to determine the output value.

[
// our other blocks...
{
opcode: 'randomBoolean',
text: 'randomness',
blockType: Scratch.BlockType.BOOLEAN
}
]
class Extension {
// getInfo, other block functions...

randomBoolean() {
return Math.round(Math.random()) === 1;
}
}

It'll should look something like this:

Our boolean in the toolbox

We can use disableMonitor again to remove the checkbox:

{
opcode: 'randomBoolean',
text: 'randomness',
blockType: Scratch.BlockType.BOOLEAN,
disableMonitor: true
}
Our boolean in the toolbox, with no monitor in sight

Next steps

How about we learn how PenguinMod handles block errors?