-
Notifications
You must be signed in to change notification settings - Fork 48
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
🐛 [bug] Ability Container fails to initialize if preloaded with multiple Abilities #23
Comments
Oh; I just saw the commentary in #10. To traverse in reverse, we could: for i in abilities.size():
var ability = abilities[-i - 1]
grant(ability) but iterating in reverse still gets mixed up. After the first grant/removal at Switching to always access the last element works, if we're to assume that each entry will always be removed. for i in abilities.size():
var ability = abilities[-1]
grant(ability) I'm not sure if the removal (movement to |
I agree with you, that system should be retouched a little bit, it's too clumsy to me now. The main logic behind the use of these two arrays is that you could add abilities without granting them (a skill tree is a good example) and grant them after when some criteria are matched. |
Makes sense! Good enough for now, and should be usable. |
* fix inventory in diablo_like example (OctoD#21) Co-authored-by: sergwest <ksendzov.sd@gmail.com> * chore: updates gitattributes * chore: adds import file * feat: adds hooks methods in Interaction (OctoD#22) feat: adds on_before_interaction_end feat: adds on_before_interaction_start chore: updates sot-like example with draggable object * chore: adds a line at the end so godot stop complaining * Fix icon paths for attribute/ability resources/nodes (OctoD#24) * fix icon paths missing "attributes_and_abilities" * add available icons to ability nodes/resources * fix abilitycontainer _ready missing preloaded abilities (OctoD#25) * fix: fixes OctoD#26 * fix: adds condition * chore(demo): adds example on how to use tags_to_display * fix: closes OctoD#23 (OctoD#28) * feat: adds _on_interaction_started and _on_interaction_ended calls (OctoD#29) this occurs when an interactable_area is interacted and if the methods are implemented (look at sot-like example) * Feat/2d-and-3d-point-and-click-controllers (OctoD#30) * feat: adds point_and_click_2d * feat: adds PointAndClick3D node * fix: fixes typo in tags_updated signal parameter name * chore(docs): adds docs * feat: adds radial menu (OctoD#31) * chore: removes commented duped line * feat: adds RadialMenuContainer icon * chore: updates readme * feat: adds initial camera shake implementation (OctoD#33) * fix: closes OctoD#34. Thank you @Hairic95 * feat: adds SlideShow node for your game intros (OctoD#35) * chore: migrates from 4.0 to 4.1 * fix: fixes test * fix: fixes esc menu button * chore: updates IDEAS.md * feat: adds get_attributes_dict method * Feat/turn-based-nodes (OctoD#36) * feat: adds turn based nodes * Update README.md (OctoD#42) * fix: closes OctoD#39 (OctoD#41) * chore: updates docs * chore: adds requirement for reproj --------- Co-authored-by: Sergwest <39670193+AFK1@users.noreply.github.com> Co-authored-by: sergwest <ksendzov.sd@gmail.com> Co-authored-by: octod <iamoctod@gmail.com> Co-authored-by: OctoD <OctoD@users.noreply.github.com> Co-authored-by: Daniel Bernard <daniel.john.bernard@gmail.com>
Description
AbilityContainer removes entries during initialization while granting, causing it to lose abilities.
To Reproduce
Create an AbilityContainer, add multiple Ability entries in the editor, run the scene and observe what abilities remain in the
abilities
Array.Details
I added a few unique abilities to an Ability Container manually in the editor, and upon running, I was receiving index errors.
Out of bounds get index '2' (on base: 'Array[Ability]')
I observed two possible issues in the code:
First, this section of the
_ready
functiongodot-gameplay-systems/addons/godot_gameplay_systems/attributes_and_abilities/nodes/ability_container.gd
Lines 199 to 201 in d634781
the
for i in abilities.size()
will return[0 ... n]
rather than[1 ... n]
, so there's no need to subtract1
. This leads to accessing the last element of the array first.Removing the
-1
or replacing this with the following should let it process in order.:Note that replacing the index iteration with objects allows the code to execute without errors, but the ability array is still missing entries even if the array changes shape (as occurs in the
grant
function).Digging into the indexing error, I found that you get odd behavior when the
grant(ability)
call is performed; since it will remove the first instance of an ability in the AbilityContainer, it removes the entry currently being granted. This causes the original array shape to change, and the loop in the_ready
function to get confused and skip entries.godot-gameplay-systems/addons/godot_gameplay_systems/attributes_and_abilities/nodes/ability_container.gd
Lines 367 to 371 in d634781
The text was updated successfully, but these errors were encountered: