Regarding the connect() function

schumiusschumius Posts: 2Member
edited January 21 in Programming

Hello guys,

I'm new to game development and programming (only have rudimentary knowledge of Python and now am studying Invent Your Own Computer Games with Python) so this might be a newbie question. I've done some searches but couldn't find the answer (or too green to spot the answer...)

Currently I'm following the Scripting section under Step by Step, Getting Started in the Godot Docs where I've learned to write the following code:

extends Panel

func _ready():
    get_node("Button").connect("pressed", self, "_on_Button_pressed")

func _on_Button_pressed():
    get_node("Label").text = "HELLO!"

I clicked on the button and got the hello text. So far so good. Then it occurred to me to remove the connect function to see if I can get the same result because I reasoned if I'd already fetched the "Button", and that the Button had already been defined with a method, then when I pressed the button the method should activate procedurally, therefore there would be no need for the connect function. So I deleted it and tried it out and it worked just fine.

So what's the difference here with and without the connect function? What am I missing?



Tags :


  • schumiusschumius Posts: 2Member
    Answer ✓

    Ahh, what a blunder. I'd connected the method to "Button" via the visual interface, that was why it still worked without the connect function. When I disconnected it, it stopped working till I put the connect function back.

Sign In or Register to comment.