Parameters and World-level methods

Slides:



Advertisements
Similar presentations
Lesson 7 C Creating a New World Method— the Dragon Captures the Princess Slides are adapted from aliceprogramming.net or
Advertisements

CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Class-level Methods and Inheritance Part 1 Alice.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Alice and Media Computation August 2009 Animation Storyboard  Code Steve Cooper Barbara Ericson.
CSC1401 Animation Creating methods/instructions (class-level)
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Parameters Alice.
Parameters Section 8-8 Web Design. Objectives The student will: Understand what a parameter is Understand how to use a parameter in Alice Understand how.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
Functions Alice.
Programming: Simple Control Structures Part 2 – Repetition Alice.
Creating and Calling Procedures Alice 3 Beta. A few choices to be made Right window, upper left hand corner start by clicking on Class “MyScene” button.
Alice Workshop November 2009 By: Kim Glavan New Lenox School Dist #122.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Variables (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS120 Lecture 04 7 September 2012.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.
Parameters Alice. A beetle band Our task is to create an animation for a bug band as an advertisement for their next concert.
Parameters Alice. Overview The need for more flexible methods Passing a parameter to a method Demos Using the Alice interface to write code for a parameter.
Parameters MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Programming in Alice Chapter 2.
Parameters Section 8-8 Web Design.
Classes, Objects, and World-level Methods
Functions Sec 51 Web Design.
Creating your Function
Functions Sec 8-11 Web Design.
Classes, Objects, and World-level Methods
Parameters Alice.
Alice and Media Computation August 2009
Programming: Simple Control Structures
Class-level Methods Alice.
Parameters and Event-Handler Methods
Creating an Animation Program
Classes, Objects, and World-level Methods
Programming: Simple Control Structures
Making Objects Move in Unison: Using Lists
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Programming: Simple Control Structures
Programming: Simple Control Structures
Parameters and Event-Handler Methods
Variables and Inheritance Part 1
Functions Alice.
Parameters and Event-Handler Methods
Programming: Simple Control Structures
Using Alice This is an introduction to Alice..
Parameters Alice.
Functions Alice.
Programming: Simple Control Structures
Classes, Objects, and World-level Methods
Class-level Methods and Inheritance
Parameters and Event-Handler Methods
Functions Alice.
Functions Alice.
Class-level Methods and Inheritance Part 2
Variables and Inheritance A More Complex Example
Presentation transcript:

Parameters and World-level methods Alice

Our Dragon world In the last class, we created methods for the dragon to take off and fly.

Storyboards Recall how we had the dragon takeOff, and how we had it fly. Dragon.takeOff Do together dragon move up 1 meter dragon flap its wings Dragon.fly Do together dragon move forward 1 meter dragon flap its wings Note that we would need very similar methods to get the dragon to land (by flying down) or to fly in other directions

A Better Solution Multiple versions of very similar code seems a bit tedious. The only things that change is the direction the dragon is to fly. A better solution is to write a more flexible method.

Parameters Built-in methods provide flexibility by providing parameters such as distance and direction. Parameters allow you to pass in values (arguments). Example Parameters: direction, distance, duration Arguments: left, 0.05 revolutions, 0.5 seconds

Kinds of Parameters Alice provides several kinds of parameters that can be used in your own methods.

The storyboard In this example, we can write just one method and use a parameter to specify: which direction the dragon is to fly. Dragon.flyInAnyDirection Parameter: whichDirection Do together dragon move in whichDirection dragon flap its wings

Demo Concepts illustrated Enter name and select the type of each parameter whichDirection is a Direction parameter A parameter acts as a placeholder in the instruction Arguments are passed to the parameter in the call to the method

A Number parameter Add a Number parameter to specify the distance the dragon travels as it is flying. Note that the call to the method must now include an argument for the distance. Traditional Lecture: Demo adding a number parameter for the height of the jump. Active learning: Students add the number parameter and revise the statement to call the method.

World-level methods It is also possible to create world-level methods These are used when there are references to multiple objects in the world

Example Consider our dragon world The dragon has taken off Now it must fly to the princess. Such a method will involve 2 objects: the dragon and the princess

Demo: Starting a new method First, to associate the new method with the World select the World tile in the Object Tree select the methods tab in the details area click on the "create new method" button

Demo Creating the flyToPrincess method

Assignment Read Chapter 4-1 and 4-2 World-level methods Parameters