How to get grandparent to change sprite2d texture based off grandchild function? Or the other way around?

Question

Hello everyone! I am very new to Godot so I am not sure if this is the best place to ask. I've watched quite a few tutorials and have had AI try to help me but I can't quite figure this out.

I am trying to make a fish-tank simulator game where you can buy fish and tanks and put them in your room. I have quite a few scenes - one of which is called “maintank” which is the room where you can set up your first tank. As part of maintank, I have a child (? which is also its own tscn) called “inventory” and inventory has its own child (? also another tscn) called “iteminfo”.

The idea is that when you buy a tank from the shop it adds to your inventory. And then when you click on the item in your inventory, a box (iteminfo) pops up with more information. From here the use button attached to iteminfo script would put that tank in the maintank scene.

As I am so new, I am not sure what the best way to go about this is. I have tried making iteminfo’s use function replace the texture of the sprite2d in maintank (placeditem) with the one that has been used in the inventory using the following code:

```gd

func _on_use_pressed() → void:
for i in Global.inventory:
if Global.inventory[i][“Name”] == ItemName:
ItemCount -=1
var tex = Global.inventory[i][“icon”]
var root = get_tree().root
get_node(“/root/maintank/Placeditem”).texture = Global.inventory[i][“icon”]
if ItemCount == 0:
var tempDic = {}
for x in Global.inventory:
if x > i:
tempDic[x-1] = Global.inventory
elif x < i:
tempDic = Global.inventory
Global.inventory.clear()
Global.inventory = tempDic
_on_close_pressed()
else:
Global.inventory[i][“Count”] -=1
get_node(“../inventorycontainer”).fillInventorySlots()

```

But it’s saying the game cannot find Placeditem anywhere?! I have also tried making Placeditem an autoload but that has come with a variety of its own issues (like the image just popping up everywhere that i don’t want it to??). Chatgpt and Google AI have said that making the grandparent node (maintank) use signals to iteminfo might help - but beyond not understanding what they mean, the code they provide has not worked and has often seemed to break things more than help anything.

Would anyone be able to help? thank you!

Please format your code like this:

```gd
# Paste your code from your editor here,
# with indentation so we can read it.
```

So it appears like this:

# Paste your code from your editor here,
# with indentation so we can read it.

Include the full script, not just the one function.

LLMs, as you have learned, will give you the wrong information. They make stuff up.

The rule of thumb is functions down, signals up.

Hi!! Thank you for the feedback. I couldn’t really figure out how to edit the scripts in here as the ``didn’t seem to want to work - so I just posted again with all the script functions etc and the``` seemed to work there!

It did not. @wchc can you take a look at this formatting, it’s the second time I’ve seen it happen in the last two days.

Looking at the “Raw” tab in the post history:

\`\`\`gd
\`\`\`

I guess the backslashs accidentally got in there from copying? Anyway, removing the backslashs should make it work.

2 Likes