Now let's explore the code that made the video on the previous page possible.
Below, you can see the code that was used to make video. It's quite complex, isn't it!
Take a moment before continuing to convince yourself that this code does carry out the plan/storyboard we've outlined. Pay attention to the Do together and the Do in order tiles, and remember that the whole tile is one big Do in order, as described at the end of the last module. Can you match each piece of code to the steps of the plan already discussed?
Now open up your code from the Alice world program you created in the previous module and make it look exactly like the code above: LastNameFirstName-First World.a2w.
(If you did not create or complete the previous Alice world program, go to the bottom of the page and download that Alice World program).
[Q2.2.1] Can you think of anything that will make this code simpler, yet still do the same actions?
In this section, we are going to learn to make our own methods. In this case, we are using methods to manage the complexity of our program. We will:
Break up our animation into logical "parts" and give each a name. I see three parts: escape, freakOut, and apologize, for when the beetle escapes, slackerProm freaks out, and ringoBeetle moves in and apologises, respectively.
Create three methods with those names and move the code that makes each part happen into that method.
In world.my first method (where we have been putting our code all this time), instead of that big complex code, we'll instead just have three instruction tiles: calling each of the methods we made.
methods to make:
This is what should be in world.my first method when we have divided the code into three different methods:
Don't forget: Download the file linked below. Launch Alice on your computer, then use File -> Open World and select the file you downloaded.
Mod2.2Starter.a2w (Mod stands for Module, 2.2 is Module 2, Section 2)
Save the world as LastNameFirstName-First WorldV2.a2w (Note: we added V2 at the end of this file name to let us know that this is version 2 of the program.)