![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | occultnix |
I’m trying to use code to determine if a “create new post” button already exists at the end of a gallery, and if not, make one. I’m finding it simple to create the button and position it and everything, but am having issues creating and connecting a signal from the button to the root Node2D in order to… you know, be able to create a new post.
Now, it’s my understanding that ‘.connect’ functions like
PARENT_NODE.connect("signal", CHILD_NODE, "signal_method"
So here’s what I’ve done (unrelated code removed for post brevity):
extends Node2D
var mainBox = get_node(".")
var gridBox = get_node("Container/PostGrid")
var newButton = Button.new()
func NewPostButton():
if gridBox.has_node("NewButton"):
print("can create New Post!")
else:
add_child(newButton, true)
newButton.show()
mainBox.connect("pressed", self, "buttonHandler_pressed")
func buttonHandler_pressed():
print("button pressed!")
But when I play the scene, I get the error
In Object of type 'Node2D': Attempt to connect nonexistent signal 'pressed' to method 'Button.buttonHandler_pressed'
I’m lost, since my understanding tells me that the syntax is correct, and that since the hardcoded object Button has a “pressed” signal in the editor, I’m a little lost as to what I’m doing wrong. Any help would be appreciated.