repeat
block code needs to be more complicated.
One potential challenge in building custom blocks that use other custom blocks is that a custom block may work fine on its own, but when it's used inside another custom block, something goes wrong.
Here is an example. A programmer intended to draw five squares in a row, like this: , and built this script:
Of course, it required a draw square
block with an input size
, so the programmer created this definition:
draw square (size)
script makes one square of size 20, as expected, when it is called with 20 as the input.But instead of getting the desired picture of five squares in a row like , the
script draws
.
What is the bug?
repeat
block code needs to be more complicated.
draw square
block draws a square of the wrong size.
draw square
block won't draw 4 sides in the shape of a square.
draw square
block actually works correctly!
draw square
block draws a square of the correct size and shape, but causes a problem that the repeat
script doesn't expect.
draw square
block doesn't return the sprite to the correct location
when it is done.
draw square
.
draw square
block leaves the sprite facing the wrong direction.
draw square
block doesn't leave the sprite facing the same way as when it started, the the repeat
script moves in different directions each time draw a square
draws a square. If there was another draw square
, all would be well.
Consider the following block definition to draw a house; if it uses a correct draw square
block, it will draw a house (with a flat roof)
and a door at the lower right:
What will be drawn if it uses the buggy draw square
code shown at the top of the page?
draw house
becomes buggy itself!
draw square
is buggy, there is no way to predict what
the picture will look like.
draw square
will do.