Cannot access script variable from PanelContainer in VBoxContainer

Godot Version

4.2.1

Question

Ok, I am missing something obvious here: I have a list of inventory items where each row is a PanelContainer which has the script InventoryListItem.gd assigned.

Now I want to loop over every row and access the variable “item” from the script but I get

Invalid get index ‘item’ (on base: ‘PanelContainer’).

My loop function below:

var inventoryListItems = %ScrollContainerInventory/VBoxContainer.get_children()
	for c in product.components:
		var p = c.product
		
		for il in inventoryListItems:
			if p == il.item.product: #here I get the error

and here the InventoryListItem.gd

class_name InventoryListItem extends PanelContainer

var item: InventoryItem

func prep(item: InventoryItem):
	self.item = item
	self.setLabels()
	
func setLabels():
	%LabelProduct.text = self.item.product.productName
	%LabelOnHand.text = str(self.item.onHand)
	%LabelDemand.text = str(self.item.demand)
	%LabelIncoming.text = str(self.item.incoming)
	%CheckButtonEnabled.button_pressed = item.enabled


func _on_check_button_enabled_toggled(toggled_on):
	self.item.enabled = toggled_on

What am I missing here?!

Can you show the scene tree when this is in action?

How would I do that to show it best here in the forum?

Oh god, I need to go to bed … :man_facepalming:
I totally forgot that the first item of the VBox was a scene called WorkorderListHeader.tscn which does NOT have that variable because it just provides the column headers.

And since I am adding it by script I did not see it anymore in the editor GUI …
Fixed that and now it iterates properly :slight_smile:

1 Like