Repetition. Add in objects. The world should look like this: Bunny Eat Broccoli Repetition Simple loops and Conditional loops

Similar documents
Lets Play Catch! Keeping Score in Alice. Overview. Set Up. Position the ball 20 feet away: Orienting the ball 7/19/2010

CS Problem Solving and Object-Oriented Programming Lab 2 - Methods, Variables and Functions in Alice Due: September 23/24

Skater World: Part Two. By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009

3. Select a colour and then use the Rectangle drawing tool to draw a rectangle like the one below.

Mapping a course for Pocket Caddy

TECHNICAL NOTE HOW TO USE LOOPERS. Kalipso_TechDocs_Loopers. Revision: 1.0. Kalipso version: Date: 16/02/2017.

Sesam HydroD Tutorial

Felix and Herbert. Level. Introduction:

Step 1. CoderDojo Milltown Exercise 1 Pong Page 1 of 13

Alice in Wonderland Tea Party Coding Animation

Get it here. Page 1 of 7 Date:Jan 8, 2014

Blackwave Dive Table Creator User Guide

Robot Activity: Programming the NXT 2.0

Student Exploration: Boyle s Law and Charles Law

Tutorial: Adding Twitch ChatPlay

Repetition Structures

ClubHub. User s Guide

ADVANCED. CATIA V5 Workbook. Knowledgeware and Workbenches. Release 16. Knowledgeware. Workbenches. Richard Cozzens. Southern Utah University

Tutorial: Setting up and importing Splat Maps from World Machine

Start a new Scratch project. Delete the cat by right-clicking it and selecting Delete.

Table Football. Introduction. Scratch. Let s make a world cup football game in Scratch! Activity Checklist. Test your Project.

User Guide. Version Mindjet

1. First start a new scratch project and remove the default sprite.

Soft Systems. Log Flume - 1. Enter Specification. Activity One ACTIVITIES. Help. for Logicator

Tutorial 2 Time-Dependent Consolidation. Staging Groundwater Time-dependent consolidation Point query Line query Graph Query

QUICK WARM UP: Thursday 3/9

Chromat Calibration Updated October 27th, 2017

Standard League WRO Football Simple Simon EV3 Training Curriculum

Technology. In the My Files [My Files] submenu you can store all the programs that you have made on the NXT or downloaded from your computer.

Wave Load Pattern Definition

For running only the scoresheet application without any video features only some very basic hardware / software requirements have to be fulfilled:

1/6 CAL.YM88 1/5 SECOND CHRONOGRAPH WITH COUNTDOWN TIMER. Instructions. Features 24-hour, Hour, Minute and Small second hands.

Start - All Programs - Class Software - Scratch - Scratch move move move Sound play drum move move move play drum Control forever forever forever

e d u c a t i o n NXT Solar Station

Scratch Hands-on Assignments CS4HS - Summer 2017

SCRATCH CHALLENGE #3

Start the Polars program and load this file by using the explorer tab on the left side. You will get following picture:

Penalty Kick in Ipanema

League Manager Tutorial

Programming a recess with interrupted cut

Here are the basic steps you need to do to get started. Each is covered in much more detail in their respective web pages.

Understood, Inc. User Guide SCUBA Solutions Version 1.7

Click on the Sequential Push Tool button you will then see the Sequential Push Control Panel.

UNDERGROUND SURVEY WITH MINEMODELLER

THSGCA Men s Compulsory Routine Document

RUNNING A MEET WITH HY-TEK MEET MANAGER

Another window pops up where you can input some parameters (called System Preferences) for your team as shown

This portion of the piping tutorial covers control valve sizing, control valves, and the use of nodes.

Integrate Riverbed SteelHead. EventTracker v8.x and above

Workshop 1: Bubbly Flow in a Rectangular Bubble Column. Multiphase Flow Modeling In ANSYS CFX Release ANSYS, Inc. WS1-1 Release 14.

Basic 1 1:00 max. Forward two-foot swizzles, 6-8 in a row

GMS 10.0 Tutorial SEAWAT Viscosity and Pressure Effects Examine the Effects of Pressure on Fluid Density with SEAWAT

Tension Cracks. Topics Covered. Tension crack boundaries Tension crack depth Query slice data Thrust line Sensitivity analysis.

Inventor Hole Notes: How to Annotate with Drill Numbers Not Diameters Author: David Ponka, Senior Applications Expert Manufacturing

Hydrus 1D Tutorial. Example: Infiltration and drainage in a large caisson. 1) Basic model setup. Sebastian Bauer Geohydromodellierung

SCIENTIFIC DATA SYSTEMS, INC. Depth Tension Line Speed Panel. DTLS Manual

Figure SM1: Front panel of the multipatcher software graphic user interface (GUI) at the beginning of multipatcher operation.

Module 3 Developing Timing Plans for Efficient Intersection Operations During Moderate Traffic Volume Conditions

Student Exploration: Boyle s Law and Charles Law

Sorcerer and Warlock

Tutorial 6a Manual Digitisation

18th Annual Verona Ice Compete USA Saturday April 28th 2018

ANNOUNCEMENT. Inclusive Skating International Canada Figure, Freestyle & Ice Dance. In Partnership with World Figure Sport.

KEM Scientific, Inc. Instruments for Science from Scientists

Energy Skate Park. Part 1-Designing a Skate Park

Creating Coastal Lots

2012 CALIFORNIA PHYSICAL FITNESS TEST. e-template REFERENCE GUIDE

Introduction to Waves. If you do not have access to equipment, the following experiments can be observed here:

Timers, Interrupts, and Square Wave Generation. Ryan Krauss. Southern Illinois University Edwardsville. October 24, 2007

Dropped Kerbs. Civil 3D 2018 Dropped Kerbs. Creating Dropped Access using Section Editor

Given below are the world functions. CompSci 4 Test 1 Oct 6, 2011

Automated Liquid Handling Station

SESSION PLAN. U11, 12, 13 & 14 Boys and Girls. Basic Beach flags Rules Basic Beach flags technique Recap Beach Sprint techniques

You are going to learn how to make a game, in which you ll use the mouse to navigate a boat to a desert island.

Online League Management lta.tournamentsoftware.com. User Manual. Further support is available online at

Skate Green Bay Compete USA Competition

Encountering Condi.ons

Inspection User Manual

Inspection User Manual This application allows you to easily inspect equipment located in Onix Work.

GEN II Robot Soccer EV3 Compass Training Curriculum Brian Thomas

Student Exploration: Uniform Circular Motion

TFC TM - Touch Force Control

Walking for Health: Scheme page guide Contents

Click the Accounting band.

Tutorial on Flange Qualification using CAEPIPE

Requesting Team Activation

Felix and Herbert. Level

KISSsoft 03/2016 Tutorial 9

The ICC Duckworth-Lewis Calculator. Professional Edition 2008

RUNNING MEET MANAGER IN SUPPORT OF MEETS (2016) Greg Wright(6/3/16) First, YOU DO NOT NEED TO DO THIS UNLESS YOU ARE THE HOME TEAM

High Strength Soft Shackle

Using the Lego NXT with Labview.

Microsoft Windows Software Manual for FITstep Stream Version 4

Sailwave Scoring Instructions for Thursday Night Races 2017

The ICC Duckworth-Lewis-Stern calculator. DLS Edition 2016

nvisti Kestrel Companion Pro For Android

What does FORCE do? FP 6: 2 ways to submit Forms C Excel sheets (as before) Highly recommended to use as from now FORCE

Free Golf Scorer. Installation: Page: 1 / 9 28/06/10

ELIMINATOR COMPETITION DRAG RACE Program Manual Firm Ver 4.11

Orange County HMIS HPRP QPR Quick Reference Guide

Transcription:

Bunny Eat Broccoli Repetition Simple loops and Conditional loops Susan Rodger Duke University July 2011 Repetition We first illustrate simple looping using loop, when you know how many times you want to repeat a section of code. Then we examine looping based on a condition. The loop continues repeating as long as a condition is true, and stops when the condition is no longer true. We also write some methods. Add in objects Drop a dummy camera to save the original camera view (always a good idea!). Add a bunny from the animals folder Add three broccoli from the Kitchen folder and inside there the food folder. The world should look like this: The broccoli spears will be floating in the air. Right click on their name in the object tree and select methods, move to, ground. That will get them on the ground. Then click on them and push them all back far behind the bunny. You can use the up/down button to move them up a little. Your world looks like:

Create new method: bunny.hop First let s teach the bunny to hop, and then to hop over to the broccoli to eat it. Click on bunny in the object tree, then the methods tab, then create new method Name the method: hop Name the method hop And you should see a bunny.hop tab now Write the method hop Drag up Do together from the bottom of the pane and put a Do in order inside it. In the Do in order drag in a bunny move up 0.5 meter Select more and set the duration to.25 sec Write the method hop (cont) Make a copy of the move command and change up to down in the second one. In the Events editor, under when the world starts, Change my First Method to bunny, then hop Now play your world

Write the method hop (cont) The bunny moves up, but not forward. Add into the Do together bunny move forward.25 Then select more, duration, 0.5 Let s get the bunny to hop in our story Click on the my First Method tab Click on bunny, methods and you should see the hop method Drag the hop method into my first method In the Events, change when the world starts to world.my first method Play again, and the bunny hops and moves forward Repeating the hop loop Click Play and the bunny hops once. We d like to get the bunny to hop 4 times. A loop allows you to repeat commands a specified number of times. Drag loop into my First Method, select other and type 4 Bunny hop 4 times Drag the hop method inside the loop and click Play. The Bunny should hop 4 times. We could add more items to the loop. Drag in bunny say and type in hop, select more and pick duration = 0.5 seconds Now the bunny hops and says hop 4 times

Loop The number of times the bunny hops is exact. We can change the number to another number, say 3 by clicking on the 4 and changing it to 3 Next let s teach the bunny to eat Now we will teach the bunny to eat one of the broccoli. We don t know how far the broccoli is, so we will need the bunny to hop over to the broccoli repeatedly until the bunny is close to the broccoli. Now the bunny hops and says hop exactly 3 times. Create new method eat Click on bunny in the object tree, then the methods tab, and then create new method Type in eat as the name You should see the bunny.eat tab Create new method eat (cont) Drag in bunny method turn to face and select broccoli To test this out, in the Events area, change when the world starts to bunny eat Then Play to see the bunny turn toward the broccoli

Create new method eat (cont) To repeat code based on a condition, we will need a while loop Drag up the while and select true How a while loop works while <condition> <code> If the condition is true, the code is executed. If the condition is still true, the code is executed again. This repeats until the condition is false, then the code in the loop is no longer executed. Create new method eat (cont) We want the bunny to keep hopping over to the broccoli as long as the distance between them is greater than 0.6 Click on world then function s tab Drag a>b into the true, select 1, and 0.6 Create new method eat (cont) Click on bunny, functions tab Drag the bunny distance to over the 1 and select broccoli

Create new method eat (cont) Click on bunny, methods tab and drag the bunny hop method into the Do Nothing Play, and the bunny heads over to the broccoli, stopping when it is closer than 0.6 meters distance. Create new method eat (cont) Now let s add some commands to bend over and eat the broccoli. Add after the while loop, commands for the bunny to turn forward.2, the broccoli to disappear (set isshowing to false) and the bunny to turn backward. bunny.eat Here is the code now for bunny.eat Click Play and watch the bunny eat the broccoli Eat all the broccoli We need to parameterize the broccoli so the bunny can eat other pieces of broccoli In bunny.eat, click on create new parameter, name it tastymorsel and select Object for type

Parameter (cont) Drag tastymorsel over all three occurrences of broccoli Now finish story First, change when the world starts back to my first method Click on the world.my first method tab After the loop put in a Do in order From bunny methods, drag in eat tastymorsel three times, selecting broccoli, broccoli2, and broccoli3. Final code for my first method Here is the final code. Play to watch the bunny eat all the broccoli. More on loop Instead of Loop 3 times, click on the 3 and select infinity times Play the world, when will the bunny eat the broccoli? Never! Infinity is dangerous to use. The statements after it never happen. Change the infinity times back to 3

If you know about lists. If you have done the list tutorial, then look at the rest of this tutorial. Otherwise you are done. You could make a list of broccoli for the bunny to eat. Under world properties, click on create new variable Name it food, select type object and select make a list Add the three broccoli to the list Food list Here is the food list And after clicking ok you should see: Now use the list In my first method disable or delete the Do in order Drag up from the bottom the For all in order and select expressions, world.food Click on bunny, methods tab Drag over the bunny eat tastymorsel into the do nothing and select expressions, item_from_food Play your world to watch the bunny eat the broccoli Final Code with List EXTRAS You could add more broccoli into the world and add them into the list to get eaten You could have the bunny move other parts when it hops, such as its feet or its head.