From NWN Lexicon
Revision as of 06:42, 17 June 2020 by Shadguy (talk | contribs) (Remarks: Expanded remarks with good info from Clippy discord today)
Jump to: navigation, search


Determines whether an object is valid.

int GetIsObjectValid(
    object oObject



The object to check the validity of.


Returns TRUE if oObject is a valid object, otherwise FALSE.


This function is a widely used utility function to check the return values for functions that return objects. While looping through objects NWN functions usually return invalid objects to signify that there are no more objects left. This function can be used to test that condition.

Most of the time, this will be the same as comparing oObject to OBJECT_INVALID. There may be times where it isn't though, so it is generally recommended that you use this function.

Related discussion from #nwnx Discord

--HA-- Can there be a difference in result between comparing OBJECT_INVALID and calling GetIsObjectValid or would it always be a bit better to use OBJECT_INVALID?

clippy They are very different. object is actually a numerical ID of the object. OBJECT_INVALID is a numerical constant that objects will never have (0x7f000000). Comparing against OBJECT_INVALID is only comparing against that particular constant. GetIsObjectValid() actually tries to look up the object by ID and return whether or not it exists in the world. For example, if you do SetLocalObject(oModule, "someitem", oSomeItem), and then destroy that item..

object o = GetLocalObject(oModule, "someitem");
GetIsObjectValid(o) == FALSE

So GetIsObjectValid() is always 'safer', but 'slower'




void main()
//Loop through all PC's in a module:
object oPC=GetFirstPC();
while (GetIsObjectValid(oPC))
   SendMessageToPC(oPC, "You're a player, aren't you? ;-)");

See Also

 author: Tom Cassiotis, editor: Lilac Soul