Class Procedures in Alice3: Reusable Code
Learn Alice in FREE step-by-step lessons.
Module 14: Class Procedures in Alice3: Reusable Code
In this module, you will create procedures. Procedures let you write code for an object to perform an action.
For instance, you can write a procedure for a biped to wave. Then, whenever you want a character to wave, you just call the procedure.
The code can then be used many times and for many objects.
This will allow you to decompose a program into functional subprograms and create and test larger programs.
We will also use parameters so that we can tell the procedure how fast to wave, or how many times to wave. We can also use parameters to tell who the bunny faces when they wave.
This a very powerful tool and will let you greatly improve the efficiency of your code.
Goals:
- Learn to create class procedures
- Create procedures for an object to perform actions such as walk or jump
- Understand the advantages of creating procedures
- Use the procedure many times and for many objects
- Decompose a program into functional subprograms
- Use parameters to give the procedure information
- Use parameters so that the same procedure can vary in speed, repetions, or distance
- Use parameters to pass an object, such as a marker, or another object
Objectives:
- Write code to animate a character, then convert that code to a procedure so that it can be used many times and for other characters.
- Utilize parameters for flexibility.
- Decompose a program into subprograms: myFirstMethod will be mostly calls to procedures and functions from now on.
Please study the material at each of the links below.
Loki Waves: Video shows statements for making Loki wave.
A Biped Waving Procedure: Copy the code for Loki waving to create procedure for any biped to wave.
Adding Parameters to a Procedure: Parameters are added so that we can vary the amount to wave and times to wave.
Witch casts spell: Parameters let us cast the spell on anything to change it to anything else.
Break the Spell: A Scene procedure is used to break the spell.
Make the dog crazy: Several Parameters
Anyone can walk: A procedure for a biped to walk can be used for any biped.
Self Study Questions: What have you learned?
Active Learning: An Exercise Class: Show what have you learned- Complete Step 6: Scene Procedures for the final project.
Discussion questions: What do you think?
Glossary for procedures lessonFull Glossary