Introduction to BYOB (build your own blocks)

byob using square block

This shows the creation and use of a Square block

Scratch itself is very simple to use: click blocks together to build scripts for the sprites (graphic items) to follow onscreen.  There are lots of support materials for this on the MIT Scratch site, but most primary school children will be playing around clicking blocks together within a few minutes of seeing the program.  All blocks are colour coded according to use, and shaped specifically so they can only be put together in certain ways.  This helps with correct syntax and takes away the agony of spelling commands correctly and getting punctuation right.

BYOB is the big brother of Scratch: With BYOB, you have the option of creating your own blocks as well, defining subroutines or functions, and then calling them from the main program.

My first block – moving in a square

In this example, I have used the block editor to create a block called SQUARE, which takes one input, SIZE, and moves the sprite in a square – REPEAT 4 TIMES: move SIZE steps, turn 90 degrees. The default value for SIZE is 50 (click on the images to see a larger version).

This means I can not only move in a square whenever I want to by using my custom block, but I can also adjust the size of the square from outside the block.

I have used the PEN DOWN block so that the sprite leaves a trail behind.

byob polygon block in action

This will allow you to specify number of sides as well

Developing – moving in a polygon

This time I have developed the block to take two parameters, size and number of sides.  I have asked for and stored both these values as variables, then used them when I called for the polygon.  A simple maths formula works out the angle of turn.

I found this a little fiddly to start with, but soon got the hang of it.  It promises to streamline Scratch code, which can get a little unwieldy at times, and offers lots of possibilities.  There are other new features in BYOB that I haven’t explored yet, but it looks as though they have good support materials for them.

Now I’ve seen how to use custom blocks in BYOB, the next step is to start using it for my virtual pet game – I’ll go straight into using BYOB rather than Scratch, as it’s basically the same thing but with extra features.

 

Advertisements

About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: