Godot - Invalid Access property issue when dragging instanciated button for inventory

Godot Version



Error: Invalid access to property or key ‘CurrentItem’ on a base object of type ‘Button(inventory_slot.gd)’

Hi! I’m relatively new to godot, but so far I’ve generally been able to troubleshoot errors on my own or by googling. This one has stumped me though. I’m following a pretty simple tutorial to make an inventory system, but I’m heavily adapting it to my needs. the github to the tutorial I’m adapting is here GitHub - finepointcgi/Godot-Horror-Game-GD at Develop2, but I’m following his video tutorial rather than copying from the github. I’m trying to implement a RE-style inventory, but so far the only real change is not to allow the stacking of items, as it doesn’t fit into my game.

There are three scenes that currently handle the inventory system: a container with the actual inventory, a scene with a button that is instantiated by the inventory to create the actual inventory, and a resource template for defining items. Pastebins to the scripts associated with the scenes can be found below

inventory - Pastebin.com - the inventory

the inventory button - Pastebin.com - the button

The template - Pastebin.com - the template

I can share any other parts of the project deemed useful. Help would be very much appreciated!

I don’t think “the inventory button” is a full script, unless it really is missing extends Button. If that is the full script you should be recieving errors like “unkown identifier ‘CurrentItem’”

If you want to paste a script in the forum use the </> button on a new line.

type or paste code here

Thanks for the tip about embedding code. The inventory slot (button) scene has a control node at its root, and the script is attached to it, not the button node directly.i made a mistake when making the paste bin <\ extends Button

var currentItem
var currentIcon
var currentLabel
var index

signal OnButtonClick(Index, item)

Called when the node enters the scene tree for the first time.

func _ready() → void:
currentIcon = $TextureRect
currentLabel = $Label

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta: float) → void:
func UpdateItem(item, index):
self.index = index
currentItem = item

if currentItem == null:
	currentIcon.texture = null
	currentLabel.text = ""
	currentIcon.texture = item.Icon
	currentLabel.text = str(item.Name)

func _on_area_2d_area_entered(area: Area2D) → void:
pass # Replace with function body.

func _on_area_2d_area_exited(area: Area2D) → void:
pass # Replace with function body.
func _on_button_down():
emit_signal(“OnButtonClick”, index, currentItem) >

The </> button is in the text editor, looks like you can also press ctrl+e. It will make the three ticks I demonstrated, which you can also write manually. That is where to paste your script, overwritting the part that says “type or paste code here”

type or paste code here

if it’s actually lowercase currentItem then the “inventory” script is wrong, trying to access a capitalized CurrentItem

Yep, thank you, one of the other devs in my studio (he had previously looked at the bug and couldn’t figure out what had happened) just committed that change. Sorry for taking your time for such a silly issue!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.