Beginner Coding with Blocks
Chapter 5
>
Level 3
Objective
Put food down and call the piglets over by putting their names on a list.
The piglets will probably be getting hungry soon, pick up the large blue bag of food and head for the two (2) dark X marks on the map. Drag & drop the place block from the Actions menu into the code editor at the two (2) dark X marks and face the trays. Drag & drop the string block from the Text menu into the place blocks and add the word "food" to the string bubble. This will pour the food from the bag into the trays for the piglets to eat.

After you're done setting down the food on both dark X marks, head to the light X mark and face the pen. Call over the piglets so they can come eat. Their names are "Peggle", "Peter", "Piper" and "Pedro". To make it easier to call them, put their names in a list, there is a set variable / create list block in the editor containing a list titled names. Enable the block and fill in the missing items.

From the Text menu, place four string blocks in the create list block. Inside them place the names of the four piglets in this order: "Peggle", "Peter", "Piper", "Pedro".

Use a for loop block to call all the names of the piglets using the speak block. The for loop uses variable x to iterate through the names list, you need to set the amount of times the loop cycles the list, that being 4 which is the amount of variables in the list.
Inside the loop, use the speak block with a create text block to combine the string "Come here " with the x variable (which will contain each name as the loop progresses). In the block editor you’ll find the blocks deactivated, enable them and finish the block sequence by adding the items in the second slot in the create text block.

Insert the list get block, dragging & dropping it from the Lists menu, this block will allow you to extract an item from the list.

In order to extract the name of each piglet from the list, drag & drop the x variable from the Variables menu into the list get block and insert it into the create text block.

Using this set of code blocks the player will be able to call out the names of all the piglets in order. The x variable in the for loop represents each name in the list as the loop goes through each item in order until it reaches the end.