ObjectId (Object function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 20: Line 20:
The <var>ObjectId</var> function can be useful in creating temporary object-specific references to other objects. For example, suppose you have <var>Widget</var> and <var>Box</var> objects in an application. The <var>Widget</var> objects do not contain references to <var>Box</var> 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 <var>Box</var> object from a <var>Widget</var> object. To accomplish this, we first declare a [[FloatNamedArraylist_class|FloatNamedArraylist]] of <var>Box</var> objects:<p class="code">%widgetBox    is floatNamedArraylist of object box
The <var>ObjectId</var> function can be useful in creating temporary object-specific references to other objects. For example, suppose you have <var>Widget</var> and <var>Box</var> objects in an application. The <var>Widget</var> objects do not contain references to <var>Box</var> 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 <var>Box</var> object from a <var>Widget</var> object. To accomplish this, we first declare a [[FloatNamedArraylist_class|FloatNamedArraylist]] of <var>Box</var> objects:<p class="code">%widgetBox    is floatNamedArraylist of object box
</p>
</p>
The idea is that the collection "names" will be the <var>Widget</var> object's id. Now, whenever a widget it put into a box or determined to be in a box, we assign that <var>Box</var> object variable to the FloatNamedArraylist item with the <var>Widget</var>'s object id:<p class="code">%widgetBox(%widget:objectId) = %box
The idea is that the collection "names" will be the <var>Widget</var> object ids. Now, whenever a widget is put into a box or determined to be in a box, we assign that <var>Box</var> object variable to the FloatNamedArraylist item with the <var>Widget</var>'s object id:<p class="code">%widgetBox(%widget:objectId) = %box
</p>
</p>
If a <var>Widget</var> is moved to a different <var>Box</var> its <var>WidgetBox</var> item must be set to point to the new <var>Box</var>. With this in place, it becomes very easy to access the correct <var>Box</var> object, given a <var>Widget</var> object:<p class="code">%box = %widgetBox(%wdget:objectId)
If a <var>Widget</var> is moved to a different <var>Box</var> its <var>WidgetBox</var> item must be set to point to the new <var>Box</var>. With this in place, it becomes very easy to access the correct <var>Box</var> object, given a <var>Widget</var> object:<p class="code">%box = %widgetBox(%widget:objectId)
</p>
</p>
==See also==
==See also==
{{Template:Object:ObjectId footer}}
{{Template:Object:ObjectId footer}}

Revision as of 05:24, 16 July 2012

Internal numeric name of object (Object class)

[Introduced in Sirius Mods 8.1]


This function returns a unique numeric id for an object.

Syntax

%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 aboject 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.

Examples

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