This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes
extends Control

onready var grid = $GridContainer
var inventory_slot = preload("res://dev/inventory/inventory_slot.tscn")

func _ready():
    for n in SaveAndLoad.runtime_data.building.keys():
        var inventory_slot_new = inventory_slot.instance() 
        if SaveAndLoad.runtime_data.building[n] == false: 
            var item_name = SaveAndLoad.runtime_data.building[n] 
            var icon_texture = load(Links.house_link[n]) 
            inventory_slot_new.connect("id_pressed" , self, "_button_pressed") 
            grid.add_child(inventory_slot_new, true) 

For each key in my dictionary -> instance scene (button) -> if key is false -> declare item name from dict -> declare texture from dict -> apply texture to button -> connect button to function (This part doesn't work) -> add button to grid container

Hey all, this is driving me crazy. I can't seem to connect my generated buttons to the buttonpressed function in my script. It has something to do with me instancing a button as a scene, since I can create buttons & connect them in a separate case.

inventory_slot_new.connect("id_pressed" , self, "_button_pressed")  

I don't get an error message either. When I click one of the generated buttons in game nothing happens.

in Engine by (35 points)

1 Answer

0 votes
Best answer

Two problems with my code, thank you to u/snikurtv for diagnosing the first, and prompting me to discover the second issue:

  • a regular button's pressed signal is "pressed" not "id_pressed"
  • I needed to parse the new button through the .connect() function

    inventoryslotnew.connect("pressed" , self, "buttonpressed", [inventoryslownew])

by (35 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.