Download presentation
Presentation is loading. Please wait.
1
Functions / Blocks
2
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
3
Types of Blocks Note the Shape: Note the Shape: Note the shape:
Command Reporter Predicate Note the Shape: Note the Shape: Note the shape:
4
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
5
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
6
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
7
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.
8
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: blocks.html?topic=nyc_bjc%2F1-intro- loops.topic&course=bjc4nyc.html&novideo&noassignment
9
Reporters and Predicates
10
Blocks that return a value - Reporters
Note the Shape:
11
Predicates - Blocks that return a BOOLean
Booleans are TRUE or FALSE values
12
How to create a visual Score
13
Visual Scores Goal
14
Visual Scores Goal
15
Visual Scores Goal
16
Visual Scores Add 2 sprites for each score
17
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.
18
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.
19
Visual Scores Add code to the “tens” digit to update the score.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.