I have been writing code professionally for decades. I have been making games before the internet. However Godot has been making me tear my hair out more than anything I’ve ever experienced in my entire life.
I was really excited when I heard about an open source game engine
However, I was very disappointed when I found out that Godot is absolutely incapable of having functional menus. The MenuButton object does not work at all. It should even exist in it’s current state. The MenuButton object allows you to add items which then appear in a popup window. The problem is, there is exactly 0 ways to interact with these parameters in the script. This should be simple. There is no excuse to for it not to be. All I want to do is create a MenuButton object and call different functions based on what menu item is clicked. I have spent hours reading forum posts with outdated solutions that don’t work. The problem seems to be with the .connect() function. It’s saying that certain arguments aren’t “callable” which I find hilarious especially since there’s no documentation for MenuButton (or PopupMenu) that provides actual use examples. All I was able to find was a list of methods. What I want to know is basically this. The MenuButton object only has “about_to_popup()” as a signal that can be sent for some reason. This is horrible. I should be able to get signals from each of the items within the menu without having to use broken .connect() function. Is there some super critical piece I’m missing? All of the tutorials and forum posts I can find are pre Godot 4.0 and are likely outdated. What is the current best and easiest way to create a MenuButton and access the information in GDscript?
A MenuButton is just that. A Button that shows a menu. In this case a PopupMenu You can access that PopupMenu with MenuButton.get_popup() and you can do whatever you need to do with that.
I’ve spent another 5-6 hours on this and basically got no where. The problem seems to be with this connect() function. I keep getting brick walled by these errors that say things like: “Invalid type in function ‘connect’ in base ‘PopupMenu’. Cannot convert argument 2 from Object to Callable.” I looked at the documentation for PopupMenu and the word “connect” doesn’t even appear on the page. I am opening an issue to fill that gap in documentation but in the meantime I have no idea what to do. I’ll provide the code so maybe someone can point out where the problem is.
I’m about at the point to just say screw it and manually draw a rectangle around it and detect mouse clicks within sections of that rectangle.
extends Node2D
func _ready():
var pmenu = $MenuPopup.get_popup()
pmenu.connect(“id_pressed”, self, “_on_menu_item_pressed” )
func _on_menu_item_pressed(id):
var selection = $MenuPopup.get_popup().get_item_index(id)
print(“test”)
For the record:
The reason why connect() isn’t described on the PopupMenu page is because it isn’t a method defined in that class.
It is a method inherited from the parent Object class.
If you look at the top of the page for any class you see this line: