Extensions |
Object classes, much like object instances, are special object-oriented Lua tables that track their own information and allow you to operate directly on them. Object classes allow you to perform some operations that don't make sense on the instance level, such as counting all the instances in the frame, or selecting a random instance. Object classes also give you direct access to objects without the inconvenience of having to export IDs or fixed values. For example, object classes can be created by name, and then be used to fetch a list of all the corresponding instances currently on the frame.
Object Class Fields (Read-Only)
These fields can be accessed, but not updated.
number | classID | Numeric ID that is unique to each class |
string | className | Name of the object class, as defined in the frame editor |
table | common | See Inheritance section below |
number | objectCount | The number of instances of this class currently on the frame |
object[] | objectList | A table containing all the instances of this class currently on the frame |
number | typeID | Numeric ID shared by all classes from the same extension (e.g. Active Object) |
Object Class Methods
These methods may be called by any object class. They are protected, so they cannot be overwritten. The colon operator, which is used by most Lua object tables, is optional here. Click on each function for more information.
object | randomObject() |
boolean | testBackdrop() |
object[] | testBackdropGet() |
boolean | testClass() |
object[] | testClassGet() |
table | testClassGetEx() |
boolean | testObject() |
object[] | testObjectGet() |
boolean | testPoint() |
object[] | testPointGet() |
boolean | testRect() |
object[] | testRectGet() |
Creating an Object Class
The static MMFI function mmf.newObjectClass() will return an object class as a table, given its name. If you call this function multiple times on the same name, it will return references to the same table. That means there can only ever be one unique copy of the object class table for a given object class. If you add your own methods or data to the object class table, they will still be there if you request the table again.
Inheritance
There is not a direct inheritance relationship between object instances and the object class that they share. They are separate entities that fill separate roles. However there's an intuitive notion that if a group of object instances all share the same class, then they should be derived from some common entity that allows them to share data and methods. For example you may have 20 instances of a chest object on your frame, and all instances should support the method "open", but you don't want to define it separately for each instance. Instead you want to define it once, at the class level, and then it should be available to every instance, even ones that might be created at a later time.
Object classes have a special table field called "common", which is the parent table for each object instance of the class. If an instance requests a field or table that doesn't exist, it will look to see if it exists in this table. You can add any number of fields or methods to this table.
Example
Copyright 2010 Justin Aquadro