Lesson 15

Arrays, Debugging

Pre-requisites: 14

Topics:

1. Building an array

2. Testing Checkpoints

3. Clearing checkpoints in order

4. Debugging the loop

Notes:

·  We create the array in advance because Alice doesn't let you remove items. If you add too many items, you have to delete the array and recreate it, which could cause problems during the lesson. There may still be a few problems if a student clicks add item at some point.

·  Built in debugging experience, since Alice will go out of bounds on the array without a check.

Introduction

Now we have a race, but there's a problem: we can just backup through the goal and win! Let's ensure we do it right! If we make sure that the driver goes through every ring, we know they went around the entire track.

[Ask for ideas how we could check this. Use questions to lead students toward checking a list of the checkpoints]

If we had a list of checkpoints, we could easily check if the driver went through a checkpoint by testing each item in the list. However, what if we want to make sure they went in the right direction?

[Use questions to lead students to checking the list in order.]

In computer science, we use ordered lists called arrays to access lists of information. We can also check a specific item in an array. If we don't check the next checkpoint until the previous one has been cleared, we know that they go through the track in order to win.

Building an Array

First we need to put the checkpoints in an array. We've created an empty array called "checkpoints", but we need to fill it up. We can find this array by clicking on “World”, then on the “Properties” tab.

Click the small gray bar to the right of "checkpoints" to open the list of items.

***DON'T CLICK ADD ITEMS. WE ALREADY HAVE THE NUMBER WE NEED! ***

Also, notice that the list starts with item 0, not item 1.

Fill in the array using the objects in the goals folder. Order is important, so they must be in the following order:

item 0 = goal0

item 1 = goal1

item 2 = goal2

item 3 = goal3

item 4 = finishGoal

To add the items to the array, click on “None” next to each item, then from the drop-down box select “goals”, then each goal as it corresponds to the item number, as shown above. Then click “OK”.

1