BYOND Developer Wiki
Advertisement

DM Reference Entry This page contains an entry from the official DM Reference.

The \ref text macro inserts a unique identification number or text string for the following embedded object (inside []'s). If the object has a tag, that will be used. Otherwise, an internal id number is used. In either case, the embedded reference is surrounded by [] brackets.

Tag var vs. reference id[]

The reason the tag is preferred is that it stands a better chance of still being valid if the object is deleted and recreated (like in a world reboot). The internal id number, on the other hand, is transient and should only be expected to remain the same for the duration of the object's existence. If you want a more permanent reference, you must assign and save the object's tag variable.

Topic links[]

The primary use for object references embedded in text is in topic links. This allows you to encode a reference to an object in the href value of a hyperlink. (Just make sure the object does not get deleted before the user executes the link. See garbage collection.)

Topic links that contain a parameter "src" assigned to an object reference are treated somewhat specially. Unless you override client.Topic() to do otherwise, the default behavior is to call the referenced object's own Topic() procedure.

Example[]

mob/verb/test()
   usr << "Click [[?src=\ref[src];action=start>here]]!"
mob/Topic(href,href_list[])
   switch(href_list["action"])
      if("start")
         usr << "Starting the game..."
      else
         return ..()

The above example uses an embedded reference to the player's own mob to create a link to a topic handled by that mob's Topic() proc. The href_list parameter is simply the result of params2list(href).

Dereferencing[]

In that example, the embedded reference was automatically converted back into an object (dereferenced) for you. If you embed references to additional objects in the href data, you would have to dereference those yourself using the locate() instruction.

See also[]

Advertisement