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:
We can use disableMonitor
again to remove the checkbox:
{
opcode: 'randomBoolean',
text: 'randomness',
blockType: Scratch.BlockType.BOOLEAN,
disableMonitor: true
}
Next steps
How about we learn how Snail IDE handles block errors?