Functions / Blocks
Why USE You have code that you are repeating in multiple places i.e. redundant code By putting in an block, you can make a change in one place and have that change affects every place you use the block Related piece of code
Types of Blocks Note the Shape: Note the Shape: Note the shape: Command Reporter Predicate Note the Shape: Note the Shape: Note the shape:
How to make a block Right-Click on the Scripting Area Select make a block … The Make a block dialog appears Select the Category Type the name of the Block and press OK
Add code to the Block Drag blocks into the scripting area within the Block Editor Click Apply Note that the block now appears in the Palette in the category that you chose – Pen in this case. Click OK Use that block like others
How to make a block with inputs Right-Click on the Scripting Area Select make a block … The Make a block dialog appears Select the Category Type the name of the Block make polygon and press OK Click the + between make and polygon The Create input name dialog appears Give the input a name sides
Make a block with inputs Add code to the script To use the input, click on the input name sides and drag it where you want to use it. Click Apply The block shows up in the palette User can input a value where sides is in the block.
Exercises Create a draw house block that uses your draw square and draw triangle blocks together to draw a "house" shape: a square with a triangular shaped roof sitting on top. (You might have to do some debugging to get the two shapes to connect properly.) Build a draw row of houses block that draws a row of attached houses, each new one to the right of the previous, until the sprite moves too close to the right edge of the screen. For that, you will need repeat until. Create a honeycomb block (with an input to let you control the size) that uses your hexagon block three times to create this design: http://bjc.edc.org/bjc-r/cur/programming/1-introduction/3-building-blocks/1-custom- blocks.html?topic=nyc_bjc%2F1-intro- loops.topic&course=bjc4nyc.html&novideo&noassignment
Reporters and Predicates
Blocks that return a value - Reporters Note the Shape:
Predicates - Blocks that return a BOOLean Booleans are TRUE or FALSE values
How to create a visual Score
Visual Scores Goal
Visual Scores Goal
Visual Scores Goal
Visual Scores Add 2 sprites for each score
Visual Scores Add in costumes for each of the digits Get costumes from C:\BYOB\Media\Costumes\Letters or the web Drag and drop the 10 costumes into each costume.
Visual scores Add code to both number sprites to orient the number correctly when the game is started. Add code to broadcast a score change Add code to receive that broadcast in the “ones” digit of the visual score.
Visual Scores Add code to the “tens” digit to update the score.