Adding items to a MenuButton using the taskbar button "Items" is very handy, but...

I can't see where to script the items. There's nothing obvious in the Items dialog, no script is added to any node in the tree.

Here are my questions: 1. Does the scripting still need to be done by hand? 2. Is there at least a skeleton script generated by adding to the Items list, but it's hiding somewhere deep in the Inspector? 3. Doesn't an item added to this list (at the very least) set up a signal somewhere?

And in case my description isn't understandable, here's what I'm talking about:

Individual OptionButton items are not nodes. This means you can't attach scripts to individual OptionButton items.

OptionButton items are stored within the OptionButton node as a property, so you can still loop over them if needed.

Thanks for the reply, Calinou.

So... if building and maintaining the Item list doesn't generate code and doesn't add properties, nodes, or anything else that cuts back on coding effort... do you have any idea what the point of it is? :)

Hi DaveTheCoder, et al.

I guess I'm not asking this very clearly, so I'll try again.

This could be a bit long-winded because I'm trying hard to be as clear as possible. Please bear with me...

So there's no misunderstanding, I'm talking about drop-down menus, the kind you'd find in any desktop application. You know, File, Edit, Help... that kind of menu.

After adding a MenuButton (not an OptionButton) to the node list, two new buttons appear above the work area: Layout and Item. (Please see the screenshot above.) The Item button (circled in red in the screenshot) brings up a dialog named Item List Editor (the right side of the screenshot above) wherein you can add menu items to the MenuButton.

After adding a few items using this dialog, I did a test and, yes, there was a drop-down menu attached to the window with all the items I'd added.

However, I hunted around in the Inspector pane, the node tree, etc. and didn't see that anything had changed. No new nodes in the node list, no new properties in the Inspector, no new signals in the Node > Signal pane, no script was attached to the MenuButton node which means there also wasn't any match statement added for handling the menu items.

As far as I can tell, I still have to add all the code for handling the menu items and—because it would have no relationship to the items in the Item List Editor —there was no point in making the list other than getting an uncontrolled and uncontrollable menu added to the window.

So, unless something is added and I simply haven't been able to find it... well, I don't get the point of having the Item List Editor.

If someone can point me in another direction, that would be great. Thanks for your patience.

I hope that clarifies things. Please let me know.

I found this article, which may help: https://godotengine.org/qa/15934/how-to-use-popupmenu-from-menubutton

So, unless something is added and I simply haven't been able to find it... well, I don't get the point of having the Item List Editor.

I suppose that the only benefit is that you can use the GUI to customize the appearance of the popup menu. The alternative is to do that in code.

As far as I can tell, I still have to add all the code for handling the menu items and—because it would have no relationship to the items in the Item List Editor —there was no point in making the list other than getting an uncontrolled and uncontrollable menu added to the window.

That's correct. You still have to attach a new script to the MenuButton, and manually code it, to handle item selections, as that article shows. I tested the code in the article, and it works.

Hmm... Okay, thanks, Dave. I just took one of the scripts I'd already written, commented out the add_item() calls and added the menu items back using the Item List Editor and got it working.

Many thanks.

So, I guess the upshot of all this is that adding menu items through the Item List Editor simply takes the place of adding them within the MenuButton script's _ready() method. Either way works. The only difference is that the add_item() method puts the code in the MenuButton script whereas using the Item List Editor adds these same lines to the top-level node of the scene.

the Item List Editor adds these same lines to the top-level node of the scene.

Maybe. I don't know if that's exactly how it works internally. There's no such node visible in the scene tree.

Otherwise, that sounds correct.

@DaveTheCoder said:

the Item List Editor adds these same lines to the top-level node of the scene.

Maybe. I don't know if that's exactly how it works internally.

It does. I looked. :)

7 months later