Pass an arg into the button.pressed.connect() function

func update_bag():
	for key in data.Items.keys():
		var new_button : TextureButton = TextureButton.new()
		var new_text : Label = Label.new()
		$Castless/Bag/Container.add_child(new_button)
		new_button.add_child(new_text)
		new_text.position = new_button.position
		new_text.position.y += 30
		new_text.text = str(data.Items[key])
		new_button.texture_normal = load("res://assets/items/"+str(key)+"/main.png")
		new_button.pressed.connect(Item_pressed, key)

func Item_pressed(key):
	print(key)
Invalid type in function 'connect' in base 'Signal'. Cannot convert argument 2 from String to int.

You can bind extra arguments, this has some limitations but should work in your case.

new_button.pressed.connect(Item_pressed.bind(key))

cool what if i want the value too?

nvm this works

new_button.pressed.connect(Item_pressed.bind(key,data.Items[key]))
1 Like

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