Method
A method is a collection of instructions, defined within an object, and which may be executed at
runtime. The collection of an object's methods define its capabilities.
There are two main types of methods:
- Standard Methods - these are predefined Mama methods such as move, turn, play sound, etc. Some of the standard methods are available only for characters (objects embedded from the characters folder in the object gallery), such as walk(), kneel() and sitOn(). The list of Mama standard methods can be browsed at the Mama reference manual.
- User defined methods - these are methods created by the user, using the program editor.
Methods can take parameters, passed to the method upon called to it. Parameters contribute to the writing a more general - thus reusable - methods, since they let the caller of the method decide on each call which values to execute the method with. For example, in the
monkey tutorial the method
switch_looks() of the object
טרוור accepts two parameters, which are the two objects to switch looks between.
Editing custom methods
You use the
program editor to edit custom methods - that is, user defined methods (standard methods are fixed and cannot be edited). In the
details area each custom method in the methods tab has
ערוך button next to it. Clicking that button will open the method for editing in the program editor. To create new method, click on the
צור מתודה חדשה button.
Editing a method:
- Using drag and drop to add instructions to the method body - each instruction within the method body is either a Mama control instruction (like כלעוד, בצע_במקביל, or a call to another method. To add a Mama control instruction you drag the instruction from the bottom of the program editor and drop it into the target line. To add a method call, you can either drag the method from the details area while the method's object is selected (the preferred way), or drag the object from the object tree to the target line, and from the cascaded menu select the required method.
- Adding variables - you can create new variables by clicking the צור משתנה חדש button, at the top of the program editor window.
- Adding parameters - you can create new parameters by clicking the צור פרמטר חדש button, at the top of the program editor window.
When creating either new variable or new parameter, a dialog box is displayed for setting the variable/parameter name,
type and value. You can create an array or a list of variables, of any of the standard
native types.