PAT - Methods (Lesson)
Methods
What is a Method?
A method is a list of instructions that can be called and used over and over again throughout the program. The method is given a name. To use the method in a given situation, call the method and provide any parameters that the method needs. The code will be executed in the method and then program continues at the next statement after the method call.
In Alice there are 3 types of methods: Procedures, Functions, and Properties. In this lesson, we will focus on the first: Procedure.
Procedure
Methods in Alice that provide the action or behavior an object can do is called a procedure. Procedural methods access abstracted code written for sizing, moving, and orienting the object. Procedures are for positioning as well as working with the object in the video.
To position objects using procedures, watch the following two videos to examine setting up the scene.
Adding a Procedure to a Class
Watch the video to learn how to add a procedure to a class (a group of like objects).
Once a new procedure is declared, code may be written in the procedure/method to be called anywhere during program execution.
The following are examples of procedures (not a complete list) from the teen person in Alice. Notice the use of verbs to indicate what is to take place, the action.
Note that these methods are only a part of all of the methods available to a teen person. Other methods include orientation, size, appearance, video, audio, timing, and even one called straightenOutJoints. This one might be useful when we use the joints of objects later in this module to create a realistic walking motion.
The ??? portions are input by the programmer based on what fine tuning details are needed for the procedure.
Notice that the top procedure is marked as editable. This is a custom procedure that has been created by the programmer to create specialized motion applicable to the story being told.
Lastly notice that Person and Biped are listed on the clip as well. Note the relationship:
A teen person is a person is a biped. Teen person is said to extend the biped class by being a more specific adaptation of a biped.
Adding other Methods to the Procedure to Create a New Procedure
Now that a new method has been added, how are other methods added to the procedure to create a new procedure.
VIDEOS SOURCED FROM ALICE.ORG Links to an external site. AND USED ACCORDING TO TERMS OF USE.