Beginner Coding with Blocks
Chapter
>
Level
Functions and Procedures
Using Conditions in Functions
Objective
Open gates and repair bridges using a single custom function by using conditions.
The path across the swamp has a few obstacles that you need to overcome, some of these obstacles are the same and you can automate traversing them by using a single custom function with conditions.
There are two types of obstacles in your way, doors you need to open and close and bridges you need to repair. Create a custom function that can go through both by setting it to take the commands "open" and "build" as arguments for the function.
Use the define function block to create a function named navigate_swamp with a parameter called action. Inside the function, use if blocks to check the value of the action parameter.
Inside the custom function, under the build condition (when action equals "build"), use the build block with "bridge" to repair the collapsed bridge in the middle of the map. Set it so the player can move forward and build the bridge three (3) times so you can get across.
For the second option in the custom function used to open and close gates (when action equals "open"), use the open and close blocks. Set it so you open a door, move forward 2 steps, then turn around (turn left twice) and close the door, then turn around again.
Walk to the dark X marks in front of doors and use the call function block to call navigate_swamp with "open" as the argument to get through gates. Also collect all the logs in the field and make your way to the first light X mark you encounter, use the call function block to call navigate_swamp with "build" as the argument to get across the stream.
Reach the exit marked by the star at the end of the path using the custom function in order to complete the level.