GetTag

From NWN Lexicon
Jump to: navigation, search



GetTag(object)

Determine the tag associated with an object.

string GetTag(
    object oObject
);

Parameters

oObject

Target object.


Description

Returns the tag of oObject. Returns an empty string if oObject is not a valid object.

PC's do return a valid value - an empty string! This is because they have no string defined as their tag (Even GetObjectByTag("") may return a PC object).



Remarks

This is probably one of the most-used and dynamic functions - by changing a creature/waypoint/objects tag, you can use it for many things, from executing scripts (On Item Activate, execute the item's tag, as a script), to checking if there is "HEY" in the tag, and if so, doing something special. The string manipulators are useful for this.

The main thing this is used for is to check if an object is exactly something, or if a script is executed, checking what the object running it is.

CopyObject() can change an object's tag - or the new one has the new tag.


Version

1.22

Example

// 1. Get our tag, then the first object by our tag - this should be
// ourselves if there is no one else with our tag in existence.
void main()
{
    string sTag = GetTag(OBJECT_SELF);
    object oSelf = GetObjectByTag(sTag);
}
 
// 2. In the OnItemActivate script, we run a script of 
// "ACT_" + Tag Of Item.
void main()
{
    string sTag = GetTag(GetItemActivated());
 
    // Execute it on the module instantly - the old GetItem calls will
    // still be valid for this item
    ExecuteScript("ACT_" + sTag, OBJECT_SELF);
}

See Also

functions: 

LocationToString



 author: Daniel Beckman, editor: Jasperre