English (United Kingdom) Hebrew

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 Trevor 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 edit button next to it. Clicking that button will open the method for editing in the program editor. To create new method, click on the create new method 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 while, doTogether, 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 create new variable button, at the top of the program editor window.
  • Adding parameters - you can create new parameters by clicking the create new parameter 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.

Right click a code entity - an instruction, a method or a function - opens a context menu, which lets you execute standard actions:
  • duplicate - make copy of the code entity right following it
  • delete - delete the code entity
  • cut - delete the code entity and add it to the clipboard
  • copy - copy the code entity into the clipboard
  • paste - paste an code entity from the clipboard into the current position
  • pop-paste - like paste, but removes the code entity from the clipboard (thus enabling sequence of paste actions on code entities copied sequentially to the clipboard)