Now let's tell a different story using the same methods. This time we're going to do more than just make a method repeat; we're going to rearrange the order of the methods. Let's make a story like the following:
Story: escape, freakOut, apologize, freakOut
So in this story, the beetle will escape. Then slackerProm will freakOut. Next ringoBeetle will come out and apologize. However, slackerProm has not calmed down yet and will freakOut again.
[Q3.3.1]: You saw how the story was turned into code in the previous section 3.2. Have a go at creating this new story now, in code. You will need to drag some/all of the method calls currently in World.My first method to the trash can, and to add some new method calls from the side bar. Remember to ensure that world is selected in the top left before adding in new method calls. Were you able to change the world to tell the new story?
If you have skipped the question and are reading this paragraph, and you are really unsure of what to do, then do read ahead. But if you have an idea but you're not totally sure about it, go ahead and give it a try. It is important to practise developing your own code.
Run the code you've created. Does it do what you expected? If not, try running it several times, with the aim of matching the actions you see with each of the instructions you've added to your code. Which instruction(s) is/are not acting as you expected?
[Q3.3.2]: If your code didn't work at first, write down what was wrong with the code and what you did to fix it?
Here's one way of creating the code (this assumes that all the code in World.My first method has been deleted):
Step 1: Make sure world is selected in the upper-left corner of the screen.
Step 2: Drag the escape method from the lower-left box into world.my first method.
Step 3: Drag the freakOut method into world.my first method under escape.
Step 4: Drag the apologize method into world.my first method under freakOut.
Step 5: Drag another freakOut method into world. my first method under apologize.
Your world.my first method should look like this:
If you haven't already run the code, do so now, to convince yourself that this works!
In the last module we learned that methods help us to manage our code more effectively and view the code at different levels of abstraction.
[Q3.3.3]: Other than for these reasons, what other advantages are there to using methods?
There are an infinite number of ways to tell the story, and you can do it all really easily since your code is structured as a set of methods that can be re-arranged and re-used.