Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NWNX_Creature_GetSpecialAbilityCount doesn't count removed abilities (with id = -1) #1757

Open
TomRotfl opened this issue May 15, 2024 · 2 comments

Comments

@TomRotfl
Copy link

TomRotfl commented May 15, 2024

When I add 2 or more abilities with different id values, if I don't remove them sequentially (last to first), but I remove the first I added as first, and then I try to remove the second, this last one will have an id value of -1 if checked, and can't be removed.

To reproduce:

  1. add a spell ability with id 880 (totally random)
  2. add another spell ability with id 881
  3. loop through the spell abilities and remove the one matching with id 880
  4. loop again, and you won't find the id 881, but you will find an ability with id -1, that can't be removed

NWNX_Creature_RemoveSpecialAbility probably doesn't reorder the list of available abilities, so on the next loop it finds an empty value and stops there (just guessing from a conversation on discord).

@Daztek
Copy link
Member

Daztek commented May 15, 2024

It's because for some reason GetSpecialAbilityCount() doesn't count the removed ones (id = -1), so in your case it'll return an amount of 1 special abilities, which you would assume to be at index 0, but it is in fact at index = 1, since when you "remove" one it just sets the ID to -1 so its spot can be reused at a later time.

So, for your repro steps:

  1. The array looks like this: [880] and GetSpecialAbilityCount() returns 1 and the special ability is at index 0
  2. The array looks like this: [880, 881] and GetSpecialAbilityCount() returns 2 and the special abilities are at index 0 and 1
  3. The array looks like this: [-1, 881] and GetSpecialAbilityCount() returns 1, so you assume the valid spellid is at index 0, but it's actually at index 1.

@TomRotfl
Copy link
Author

Interesting! Adjusting the title name to reflect the real bad guy here

@TomRotfl TomRotfl changed the title NWNX_Creature_RemoveSpecialAbility doesn't re-order the list of available abilities on the creature NWNX_Creature_GetSpecialAbilityCount doesn't count removed abilities (with id = -1) May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants