ObjectId (Object function)

From m204wiki
Jump to navigation Jump to search

Internal numeric name of object (Object class)

[Introduced in Sirius Mods 8.1]

This function returns a unique numeric id for an object.


%number = object:ObjectId

Syntax terms

%numberIs the online-wide unique id of the object.
object Object object for which id is to be returned. Of course, since all classes extend the Object class, object can be of any class.

Usage notes

  • As noted above, the object ids are unique in an Online. However, they are not unique between Onlines nor between runs of an Online.
  • The object ids are assigned in numeric order starting at 1. So the first object instantiated in an Online run has object id 1, the second has object id 2, and so on. Since the object ids are online-wide, there is no guarantee that an object instantiated right after another object in the same request will have an object id one greater than the previous one's. This is because other objects for other threads (users) might instantiate an object between the two instantiations in the request.
  • The id is a characteristic of the object, not the object variable. As such, the same value is returned for a given object, regardless of what variable is used to obtain the id and regardless of the class of the variable used to invoke the Objectid method (base class or extension class).
  • XmlNode objects return the id of the containing XmlDoc object.


The ObjectId function can be useful in creating temporary object-specific references to other objects. For example, suppose you have Widget and Box objects in an application. The Widget objects do not contain references to Box objects because boxes don't have much to do with widgets. However, in our specific application, we are tracking widgets in boxes so it would be very useful to be able to get a Box object from a Widget object. To accomplish this, we first declare a FloatNamedArraylist of Box objects:

%widgetBox is floatNamedArraylist of object box

The idea is that the collection "names" will be the Widget object ids. Now, whenever a widget is put into a box or determined to be in a box, we assign that Box object variable to the FloatNamedArraylist item with the Widget's object id:

%widgetBox(%widget:objectId) = %box

If a Widget is moved to a different Box its WidgetBox item must be set to point to the new Box. With this in place, it becomes very easy to access the correct Box object, given a Widget object:

%box = %widgetBox(%widget:objectId)

See also