By Deborah Nelson
Duke University, July 13, 2008
Under the direction of Professor Susan Rodger
As you follow the instructions below, click on an image to enlarge it.
Then use the'go back one page' arrow in your web browser to come back to
Loading the World
Open a new world, with the template of your choosing. Save it in a directory
that you can find again. First: After you have opened the file, and set up your world, go
into the "Layout" mode by clicking on the green button 'Add Objects' (toward the middle of
Click 'more controls.' Click 'drop a dummy at the camera.' Rename the dummy
'originalPosition.' To leave the layout mode, click 'done'
This is something you should always do when you make a world in case you need to return the
camera to this view later. If you don't understand dummys,look at the camera control tutorial
- The objects we will add are in the ocean folder in the web gallery: OceanFloor, Shark and
- OR in the local gallery, use the shark and lilfish from the Animal folder
How to add objects to your scene
- First, drag the oceanFloor into your world
- In order to add the shark and lilFish2: drag each into your world instead of clicking on add instance
Once you drag the object into the screen, BEFORE you drop the object (release the mouse),
hold down the shift key and move your cursor forward (into the scene) until you see the yellow outline box. Then drop the object.
- If you still canít see your objects, drag the oceanFloor away from the camera. Move the fish up and then
move your oceanFloor back
Writing the method
- Create a world-level method named sharkChase
- Drag the following instructions into the method:
Create a BDE
- Click on create new event
- Select while something is true
- This event is a while loop with three parts:
The BDE: the conditional
- The first step in writing a BDE is the conditional.
- We want this loop to run while the shark is more than one meter away from the lilFish.
- Click on world in the object tree and go to functions. Drag a>b on top of the
- Select 1 for a and b (as placeholders).
- Click on shark in the object tree
- Click on the functions tab
- Drag the shark distance to function on top of the first 1. And in the drop down,
select lilFish2, the entire lilFish2.
The BDE: the Begin
- The very first time this while loop is passed, we want the shark to say: Where are you?.
- From the object tree, drag the shark on top of the Nothing beside Begin.
- Select the say method and other. Type in: Where are you?
The BDE: the During
- Every time the while loop is passed, we want the sharkChase method to be called.
- Click on world in the object tree and click on the methods tab.
- Drag world.sharkChase onto the Nothing beside During.
The BDE: the End
- The very last time the while loop is passed, when the shark is 1 meter away from the fish,
we want the shark to say: Gotcha
- Drag the shark say method on top of the Nothing beside End.
- Select other and type in: Gotcha.
Re-setting the BDE conditional
- Play your world. The while loop only happens once. Letís create a way to reset the
- Click on create new event and select Let the mouse move
- Click on Any Object and select create new list
- Name the list animals
- With type object
- Add the shark and lilFish2 as the new items.
Play your world
Now when you play your world, after the shark says Gotcha, click on either the shark or
the lilFish2 and move it around the screen.
Then, the BDE loop will happen again.
To move the objects up or down, hold down the shift key while you click
To change the direction the objects are facing, hold down the control key while you click
Write a new method
- In the method's tab of the world details panel click create new method. Name it
- Drag the following code into your method:
- Create new event: while something is true
- An empty BDe appears in your event editor
- Right click on this new event and select change to when something becomes true
When something is true: The conditional
- The conditional is when the fish distance to the shark is less than 1 meter
- This event is useful because sometimes, we only want something to happen once instead of
called again and again in a loop.
- Add the conditional to your event to look like this:
- Drag in a Do in order on top of the Nothing in this event.
- Drag wait 0.5 seconds and the fishCircle method from the world details panel into the
do in order
- Play your world
Recap of BDE
- A BDE is a type of while loop
- The Begin will only occur the first time through the loop
- The During occurs every time the while loop is being iterated through
- The End will only occur the last time through the loop
- In your world, it is useful to have something to reset the conditional of your BDE
- Or, you can change your BDE to when something is true when you donít need a loop, then
it only happens once