2.4. Blocks (Functions)ΒΆ

Functions (also called subprocedures or in BYOB, Blocks) are a powerful tool for building abstractions and reusing code.

The video below introduces them in BYOB:

Checkpoint Exercise

Triangle Block:

Make a block that draws a triangle. It should look like the picture below and clicking it should result in the sprite drawing a triangle.

../../_images/CP23a.gif
../../_images/CP23a_key.gif

Flexible Block:

Make a block (or modify your last one) that draws a triangle of a specified size. It should look like the picture below and clicking it should result in the sprite drawing a triangle where each side is the length specified in the parameter (input hole in the block).

../../_images/CP23b.gif

Note

You should NOT use Ask [ ] and wait block inside the draw triangle block. The input to the block should come from the parameter (hole where a value can be placed).

../../_images/CP23b_key.gif

Multiple Triangles:

Make a block that draws a number of triangles that you can specify via a parameter.

This: cp23c1 should result in cp23c2

Note

You should NOT use Ask [ ] and wait block inside the draw triangles block. The input to the block should come from the parameter (hole where a value can be placed).

../../_images/CP23c_key.gif