Difference between revisions of "GetObjectByTag"

From NWN Lexicon
Jump to: navigation, search
(Created page with " =GetObjectByTag(string, int)= Retrieves an object based on the tag given to it. object  GetObjectByTag(      string  sTag,  ...")
 
Line 7: Line 7:
 
Retrieves an object based on the tag given to it.
 
Retrieves an object based on the tag given to it.
  
 +
<nwscript>
 
  [[object | object ]] GetObjectByTag(
 
  [[object | object ]] GetObjectByTag(
 
      [[string | string ]] sTag,
 
      [[string | string ]] sTag,
 
      [[int | int ]] nNth = 0
 
      [[int | int ]] nNth = 0
 
  );
 
  );
 +
</nwscript>
  
 
====Parameters====
 
====Parameters====
Line 48: Line 50:
 
====Example====
 
====Example====
  
<font color="#007f00">// Demonstrates how to retrieve an object with the GetObjectByTag() funciton and apply a spell effect to it.
+
<nwscript>
  </font>
+
// Demonstrates how to retrieve an object with the GetObjectByTag() funciton and apply a spell effect to it.
  <font color="#0000ff">void</font> main()
+
   
 +
  void main()
 
  {
 
  {
       <font color="#007f00">//makes the world appear dark to NPC Bob
+
       //makes the world appear dark to NPC Bob
</font>    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDarkness(), GetObjectByTag(<font color="#00007f">"NPC_BOB"</font>));
+
      ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDarkness(), GetObjectByTag("NPC_BOB"));
 
  }
 
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 21:43, 25 August 2012



GetObjectByTag(string, int)

Retrieves an object based on the tag given to it.

 [[object | object ]] GetObjectByTag(
     [[string | string ]] sTag,
     [[int | int ]] nNth = 0
 );

Parameters

sTag

The tag of the object to search for.

nNth

The Nth object with this tag may be requested. (Default: 0)


Description

Returns the nNth object of the specified tag or OBJECT_INVALID if the object cannot be found.

sString cannot be "", this will return OBJECT_INVALID.



Remarks

The nNth parameter has been determined to return the nNth object with the specified sTag starting at position 0. Outside of the current area, the scan will begin starting with the last (most recent) area added to the module following this hierarchy:

OBJECT_TYPE_STORE (128)
OBJECT_TYPE_PLACEABLE (64)
OBJECT_TYPE_WAYPOINT (32)
OBJECT_TYPE_AREA_OF_EFFECT (16) (spell effects, like web)
OBJECT_TYPE_DOOR (8)
OBJECT_TYPE_TRIGGER (4)
OBJECT_TYPE_ITEM (2)
OBJECT_TYPE_CREATURE (1)

GetObjectByTag can also be used to get areas, but not the module (use GetModule() instead). It is unknown what will be returned if an area has the same tag as a non-object area.


Known Bugs

The feature of "" returning player characters (IE: Those objects without a tag) has been fixed or changed in 1.64, and now properly returns OBJECT_INVALID.


Version

1.61

Example

 // Demonstrates how to retrieve an object with the GetObjectByTag() funciton and apply a spell effect to it.
 
 void main()
 {
      //makes the world appear dark to NPC Bob
      ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDarkness(), GetObjectByTag("NPC_BOB"));
 }

See Also

functions: 

GetTag



 author: Sarev0k, editors: Jasperre, Mistress, additional contributors: David Scott, Glenn Berden, Lilac Soul, Jeff Robertson, Kolyana