From NWN Lexicon
Revision as of 22:18, 21 August 2022 by Jasperre (talk | contribs) (→‎Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

A pointer to an object in the module. Objects can be areas, areas of effect, creatures, doors, encounters, items, placeables, stores, triggers, waypoints, and even the module itself.

Object definitions such as "object oObject;" start as OBJECT_INVALID and functions usually return OBJECT_INVALID on error, such as not finding a object with GetNearestObject. See OBJECT_INVALID for further info.

You can use ObjectToString to see how the game references these IDs which are internally just a number. PCs are referenced from 7FFFFFFF (or 0x7FFFFFFF if you were able to define it yourself as an int) downwards, while objects start at 0 (or 0x00000000 if you were able to define it as an int) and work upwards. This may be useful for when GetIsPC fails in some game edge cases - see that article for details. The player ID is generated on login, and retained until the server is restarted. https://nwnlexicon.com/index.php?title=Object&action=edit You can't do StringToObject or IntToObject so these numbers are otherwise only useful for debugging. Instead you can save/load these with SetLocalObject and GetLocalObject or loop them with various other functions.

To see a bit about this see the NWNXEE source code.


// We usually prefix object references with "o" for "object":
object oPC = GetLastPlayerDied();
object oPC; // This begins as OBJECT_INVALID

oPC = GetFirstPC(); // This is the first PC or DM object, or if no PCs are connected to the server it will be OBJECT_INVALID

oPC = GetNextPC(); // This assigns the next PC or DM object to the oPC reference. If no second PC or DM exists it will be OBJECT_INVALID
// Set oPC to the first PC in the module
object oPC = GetFirstPC();

// You can assign a new reference to what another reference uses, in this case oFirstPC now is the first PC in the module
object oFirstPC = oPC;

// Note the below code does not change what oFirstPC is assigned, ie oFirstPC still is the first PC, it doesn't suddenly become the second PC
oPC = GetNextPC();

See Also