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

[Inventory] Invalid call when using add_item() function for the InventoryBag node #29

Open
KometFox opened this issue Dec 30, 2020 · 3 comments

Comments

@KometFox
Copy link

While I tried to follow some of your Inventory addon tutorials I stumbled upon some issues, I managed to rewrite the "_generate_item()" function as "_get_item(id, category)" so that its being used to load valid (I think?) item entries that gets added to a dictionary variable, now when I use this "_get_item(id, category)" function to add a item to the InventoryBag node I get this error: Invalid call. Nonexistant function 'disabled_slots_occupied' in base 'Nil'.

When I use the "add items" code example and try to add the item that way I get the same error.

Debugger output:

0 - res://addons/keh_ui/inventory/bag.gd:948 - at function: _get_colliding_data
1 - res://addons/keh_ui/inventory/bag.gd:1029 - at function: _find_fitting_spot
2 - res://addons/keh_ui/inventory/bag.gd:164 - at function: add_item 
3 - res://System/Inventory/Init.gd:19 - at function: add_items
4 - res://System/Inventory/Init.gd:14 - at function: ready 

Node2D, InvDemo.gd script: https://ghostbin.com/paste/km8Ek

Node, Init.gd script: https://ghostbin.com/paste/8yRFk

@Kehom
Copy link
Owner

Kehom commented Dec 30, 2020

OK. That's probably a big problem of how I "faked" static variables.

Just to test things, could you please test deferring the call to add the item into the bag? Either by

call_deferred("add_items", item)

in the _ready() function or

InvBag.call_deferred("add_item", idata)

in the add_items() function?

Problem here is that the bag (and the special slot) require internal initialization that is deferred because the tree is not fully built when the code is run. The result of that is the internal variable is null until the next main loop iteration.

Now, even if this works, please just notify me without closing the issue. I will use this as a reminder that I need to review the code and try to find a better solution related to the initialization in order to avoid this kind of problem.

@Kehom Kehom closed this as completed Dec 30, 2020
@Kehom Kehom reopened this Dec 30, 2020
@KometFox
Copy link
Author

@Kehom
The call call_deferred("add_items", item) fixed it and now the item shows up correctly and so far it can be used now, thanks for the quick reply I appreciate it. It did made me wonder because when I looked at your original invdemo.gd script the button function that adds the item is not relying on this function.

@Kehom
Copy link
Owner

Kehom commented Dec 30, 2020

That happens because when the button is pressed it's almost certain that the initialization will be completed when it is pressed. I doubt someone will be able to press it on the very first frame of execution!

The thing is, the initialization of the inventory system only finishes at the end of the very first frame in which it was loaded. This means that certain operations will fail if executed before that initialization could occur. Buttons rely on events that occur after this initialization.

I will review the code and try to find a solution that removes the requirement of delaying the call. And if I can't find one, try to make it more clear about this limitation.

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