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.
+3 votes

I created them in the designer, adding a few buttons. I get an item list... but how do I connect to "pressed" with each button?

This is Godot V3.0

in Engine by (260 points)

I believe the second half of that step by step guide will give you what you need
http://docs.godotengine.org/en/3.0/getting_started/step_by_step/scripting.html

I know how to connect ordinary buttons but how do I connect buttons in a MenuButton? I can't select them in the editor, they're in a modal dialog.

In case it helps anyone, it's hard to find out how to edit the popup items for a MenuButton. You can't do it in the Inspector; an "Items" button appears in the header of the main viewer when you select the MenuButton in the scene. Click that to edit the items.

1 Answer

+6 votes
Best answer

Ok, so after a bit of digging and testing(like 10-20 minutes) i found out that you need to use the get_popup method and connect the id_pressed signal from that popup that you got, aka like this:

get_popup().connect("id_pressed",self,"func_name")

and the function is set like this:

func func_name( ID ):
      # Some Beautiful Code Here <3

and ID is the number of the item that was selected...

hope i helped this time was fun exploring it tho

by (1,205 points)
selected by

Bingo!

extends PanelContainer

onready var menuButton = $Panel/MenuButton

func _ready():
    var popup = menuButton.get_popup()
    popup.connect("id_pressed", self, "file_menu")

func file_menu( id ):
    match id:
        0:
            print("new")
        1:
            print("open")
        2:
            print("save")
        3:
            get_tree().quit()

And a match statement!

registered here to say thank you, spent my whole day looking for this staff

How do you do this in Godot 4?
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.