<< Chapter < Page | Chapter >> Page > |
Selection structures are created by dragging these blocks into the center pane in order to apply them to a particularsprite.
The bottom block in Image 11 is used to select between two specific actions. The middle block is used when there is only one action and you need to decidewhether to take that action or not. That is the case in this program. If the basketball is touching a beach ball, a specific action is required.If the basketball is not touching a beach ball, no specific action is required.
Note the empty darker depressed area in each of the blocks shown in Image 11 (the rectangle with the pointed ends) . In order to use either of these blocks, you must drop another block having the same shape into the depressedarea. The block that you drop into that area must specify the condition that will be used to make the decision.
Unless I missed seeing some others, there are only two buttons at the top left of Image 4 that expose blocks having the required shape:
In this case, we will select and use a block from the light blue Sensing group. (We will use programming blocks from the green Operators group in a future module.) All of the blocks belonging to the Sensing group are shown in Image 12 .
We will use the block labeled touching followed by a pull-down list and a question mark.
The items that appear in the pull-down list depend on the sprites that have been added to the program. Forthis program, that list consists of the following choices when the basketball has been selected for programming:
The top two choices are always there. The remaining choices depend on the sprites that have been added to the program at the point in time when youpull down the list and the sprite that has been selected for programming. (Note that the Basketball sprite does not appear in the above list because it was selected for programming when I examined the list. In otherwords, you can't determine that the basketball is touching the basketball.)
Getting back to the bottom script in Image 8 , you can see that I dragged two copies of the if block shown in Image 11 into the center panel and connected the blocks as shown in Image 8 . Then I dragged two copies of the touching block from the Sensing group shown in Image 12 , and dropped each of those blocks into the corresponding locations in the if blocks in Image 8 .
Then I selected RightBeachball from the pull-down list for one of the touching blocks and selected LeftBeachball from the pull-down list for the other touching block.
At this point, I had the conditions for the two selection structures established, but I hadn't yet specified the actions to be taken when one or theother of the conditions is found to be true.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?