Skip to content

Help Please - Type Object

Having noticed that according to the lexicon, a variable of type object is just a single int, I sat down and thought about how this would work. Having thought about it for a while the most efficient solution I could come up with was this -
Given that the value held by a variable of type object is just a simple int, how does this work? The games engine holds a list of everything that you have placed into the game. In order to accommodate those things created and/or destroyed during the course of the game, this list is what is termed dynamic. That is it can expand and contract as the need arises. This list in turn points toward the actual data of these things and the int is an index into the list.

My question is quite simple really. Is the above true? Is that how the NwN EE game engine actually works or have I missed something or am I totally wrong?

All help gratefully accepted.

TR

Comments

  • FreshLemonBunFreshLemonBun Member Posts: 909
    I have always assumed so if I understood you correctly. Like when people have script bugs with objects what is usually happening is about the reference, the data is gone but the reference still exists in the script.
  • WilliamDracoWilliamDraco Member Posts: 175
    edited March 2021
    Yes - the 'object' type is a reference type (or "pointer" - the term that C/C++ uses for this) to the actual object data.

    The Object table is generated on each run, with almost all objects starting from 0x00000000 (the module is always object 0) and players starting from 0x7FFFFFFF (INT_MAX) counting down.

    As the table is generated each run, this is why SetLocalObject can't truly persist - It is only the reference, but on the next run the table may be generated in a different order, and therefore the reference/pointer will point to a different actual object.
  • ForSeriousForSerious Member Posts: 446
    Initially I was thinking it would be a hash table, but I suppose you would get better performance with an array. That being the case, it would not be able to expand nor contract. It would be initialized at the max size and rely on the sheer size of the integer type to never be exceeded.
  • WilliamDracoWilliamDraco Member Posts: 175
    Some people tried to make a module specifically to break this limit just to see what happens. The module consistently broke not even 1% of the way to INT_MAX. there are many many limits before a server runs out of objectIDs
  • TarotRedhandTarotRedhand Member Posts: 1,481
    Thanks guys
    ForSerious wrote: »
    Initially I was thinking it would be a hash table, but I suppose you would get better performance with an array. That being the case, it would not be able to expand nor contract. It would be initialized at the max size and rely on the sheer size of the integer type to never be exceeded.

    Depending on the programming language used, altering the size of an array is not necessarily a problem. Even if it were, in languages such as C++ you can create (if it isn't a built-in object) an object called a sparse array which allows for such expansion/contraction amongst other things.

    TR
Sign In or Register to comment.