nwnxee / unified

Binaries available under the Releases tab on Github
https://nwnxee.github.io/unified
GNU General Public License v3.0
129 stars 92 forks source link

NWNX_Data unexpected insert behavior #428

Closed ELadner closed 4 years ago

ELadner commented 5 years ago

The "Insert" function doesn't behave like an insert, it behaves like an Update.

Either it's named poorly or it's behavior needs to be adjusted.

Code below with server output (shortened) and annotations interspersed.

    WriteTimestampedLogEntry("=================================================");

    WriteTimestampedLogEntry("A - Current Contents:");
    DumpArray(o, SKILL_NAMES_ARRAY);

I [13:38:05] [...] [....cpp:95] (Server) A - Current Contents:
I [13:38:05] [...] [....cpp:95] (Server) Element 0 = Alchemy
I [13:38:05] [...] [....cpp:95] (Server) Element 1 = Athletics
I [13:38:05] [...] [....cpp:95] (Server) Element 2 = Enchanting
I [13:38:05] [...] [....cpp:95] (Server) Element 3 = Mechanics
I [13:38:05] [...] [....cpp:95] (Server) Element 4 = Mining
I [13:38:05] [...] [....cpp:95] (Server) Element 5 = Sailing
I [13:38:05] [...] [....cpp:95] (Server) Element 6 = Tracking

    WriteTimestampedLogEntry("=================================================");
    WriteTimestampedLogEntry("Erase the 3rd entry (at=2, contents Enchanting");
    NWNX_Data_Array_Erase(NWNX_DATA_TYPE_STRING, o, SKILL_NAMES_ARRAY, 2);

    WriteTimestampedLogEntry("B - Current Contents:");
    DumpArray(o, SKILL_NAMES_ARRAY);

// Third element ("Enchanting") was deleted and the array is now 6 elements long
I [13:38:05] [...] [....cpp:95] (Server) Erase the 3rd entry
I [13:38:05] [...] [....cpp:95] (Server) B - Current Contents:
I [13:38:05] [...] [....cpp:95] (Server) Element 0 = Alchemy
I [13:38:05] [...] [....cpp:95] (Server) Element 1 = Athletics
I [13:38:05] [...] [....cpp:95] (Server) Element 2 = Mechanics
I [13:38:05] [...] [....cpp:95] (Server) Element 3 = Mining
I [13:38:05] [...] [....cpp:95] (Server) Element 4 = Sailing
I [13:38:05] [...] [....cpp:95] (Server) Element 5 = Tracking

    WriteTimestampedLogEntry("=================================================");
    WriteTimestampedLogEntry("Add a new third entry");
    NWNX_Data_Array_Insert_Str(o, SKILL_NAMES_ARRAY, 2, "NewThird");

    WriteTimestampedLogEntry("C - Current Contents:");
    DumpArray(o, SKILL_NAMES_ARRAY);

// ???  Inserting a new value at the third slot overwrote "Mechanics" with "NewThird" instead of 
// creating a new slot, inserting "NewThird" as the new third element pushing "Mechanics" to the
// fourth.
I [13:38:05] [...] [....cpp:95] (Server) Add a new third entry
I [13:38:05] [...] [....cpp:95] (Server) C - Current Contents:
I [13:38:05] [...] [....cpp:95] (Server) Element 0 = Alchemy
I [13:38:05] [...] [....cpp:95] (Server) Element 1 = Athletics
I [13:38:05] [...] [....cpp:95] (Server) Element 2 = NewThird
I [13:38:05] [...] [....cpp:95] (Server) Element 3 = Mining
I [13:38:05] [...] [....cpp:95] (Server) Element 4 = Sailing
I [13:38:05] [...] [....cpp:95] (Server) Element 5 = Tracking
Liareth commented 5 years ago

Set would probably be a better name for it. I have no idea why I called it Insert.

ELadner commented 5 years ago

Is this waiting for an NWN:EE version bump for deployment (since technically it's an API behavior change)?

Daztek commented 5 years ago

Yeah, it's a bit of a breaking change that can't really be added without breaking backwards compatibility.

I'm thinking of adding it with 64bit version of NWN/NWNX where we'll probably be moving around / changing other things too.

mtijanic commented 4 years ago

Fixed in 64bit branch, closing.