Passing resource data through signals and functions

Godot Version

4.3

Question

I return once more with familiar questions, after changing things around in my code a bit, and getting stuck again… one day I will hopefully get it into my noggin.

I have a group of resources called “item” with their own variables, all stored in a bigger variable called “inventory”. Inventory is defined in an autoload script, so it can be accessed everywhere.

I add things to the inventory with a “get_item” button, that seems to work halfway:

When “_on_get_item” is called, it appears to still hold and access all the data in the Item just fine, when doing the test print. But maybe it doesn’t carry over to the next “update” function as well, as I get an error on line 27 here:

How do I make sure to keep passing it on and accessing the “amount” variable?

what exactly is the Inventory.inventory variable?

Inventory.inventory is an array, holding the item resources.

The item resources are set up like this:
billede

The inventory array has them added through the Resource Group addon, so I don’t have to do it manually. It’s set up in the inventory autoload like this, if it helps:
billede

Can you print out the content of the inventory variable before the for-loop?

I can! I put an extra button to test this, and it seems to work:

billede

okay can you print out the value of item inside the for-loop?

Hmmm I tried adding this now in the for-loop:
billede

And it prints this:
billede

So that looks like it actually does read the amount variable? So wonder why I still get the other error then.

Did you put it inside the update-method for-loop?

I did yeah, here’s all of it in context:
billede

and this still throws an error at the if-statement?

Indeed, it still stops the game and gives this result:

No now it throws an error at the print. please only print the value of item:

print(item)

Oh right, true. I changed it to item:

What resources are inside the resourcegroup you are loading?

All of these test items for now:
billede

They are all set up like this:
billede

The printed array contains 6 resources, but apparently you only load 5. for some reason theres a resourcegroup inside the array

Oh! You’re right, the group is in the same folder as the items. I just tried moving it, and now I don’t get the error. Everything works, adding in the children with the correct data and all.

Thank you so much for the time to go through it for me! I was sure I had entered some code wrong, not just placed the group in the wrong place.

1 Like