Vehicle / Conditionals Tutorial

In this tutorial, we will complete two demonstrations of the vehicle property. In the first demonstration, we will create a changeVehicle method to alter the Vehicle Property of the Philosopher, depending on its current state. In the second, we will be playing with the Vehicle property of the camera instead. Over the course of the tutorial, we will get some practice with making decisions using (If/Else).

Part 1: Philosopher Riding the Humvee

Please download the starting world here.
As soon as you finish loading the world, click play, and use the mouse to drag the Humvee and the Philosopher around. For the purposes of this tutorial, you can ignore the parts of the program that allows you to do this in the first place. Just realize that you can do it. Now, I promised that we would play with the vehicle property as well as conditionals. In the initial download, you should notice that a method has been created for you, called "changeVehicle." In this part of the tutorial, we will fill in that method:



Click on "Edit" to open the method.



Now, you should see the method open in the method editor:



Our goal is to write code so that, if the philosopher's vehicle is currently the Humvee, then let's remove the connection of the philosopher to the Humvee by setting his Vehicle to the world. Also, if the reverse is true, we want to make the philosopher's vehicle to be the Humvee. To accomplish this, we need an If/Else (also called a "conditional" because you are making a decision based on a condition) statement. Drag this up from the bottom over the Do Nothing:



Just choose True in the dropdown menu. (We will replace this later.) When you've completed the drop, your method editor should look like this:



Now, we want to check something about the vehicle property of the philosopher, so click on his name (euripedes), click properties, then drag the Vehicle property over the true in the if statement:



When you drop it, Alice will prompt you with a drop-down menu asking what the vehicle should be equal to. Go through the drop-down menu until you come down to Humvee. See the screenshot below.



When you are finished with this step, your screen should look like this:



Now, anything you put under the if part of the statement will only be executed if the vehicle of our philosopher is equal to the humvee. We want our method to negate this if it is true. Drag the Vehicle property again, this time under the if (this action will prompt Alice to ask you to set it to some value). Choose "the entire world" in the drop down menu.







Now, your code should look like this:



Finally, we want to make so that if the Vehicle of the philosopher is not the humvee AT THE TIME THE METHOD IS CALLED (when T is pressed), the Vehicle of the philosopher suddenly becomes the Humvee. Drag the Vehicle of our philosopher again, this time under the Else part, and choose Humvee in the drop down menu:







Now, your code should look like this:



Play your world. Drag the Humvee around, and drag the philosopher. Then, press T and drag the Humvee. Notice that the philosopher moves with it now. Press T again to reverse this condition. You can download the completed world here.

Part 2: Camera Riding the Humvee

Please download the starting world.
The only real difference between this world and the other one is that the arrow keys do the controlling rather than the mouse, and the philosopher always rides the humvee. Take a few moments to play with this version of the Philosopher-Humvee world, where the keyboard controls the humvee, which the philospher is riding. Now, please follow all the instructions above, replacing euripedes with camera at each step. When you are done, you should have a world where you can have the camera follow the humvee, or you can move the humvee by itself . The completed code (to be placed in the changeVehicle method) looks like this:



When you play it again, press T to have the camera follow the humvee, and press T again to disengage the two. Download the completed world.


Professor Rodger's Homepage

Main Tutorial Website

Alice Materials at Duke