4.1 Menu Buttons
Asked Answered
A

2

0

Hi,

I'm trying to add a 'File Menu' a the top of my project. I'm following this tutorial
But this syntax doesn't seem to work anymore. I can't find the right way to do this in the docs either. Does someone know how to do this correctly?
This is the error I'm seeing as well:

Code:

func _ready():
	node_graph = $VBoxContainer/MainWindow/GraphContainer/GraphEdit
	file_menu = $VBoxContainer/HBoxContainer/HBoxContainer2/FileMenu
	
	file_menu.get_popup().connect("id_pressed", self, "on_item_pressed")
	
	
func on_item_pressed():
	print("Hello")

Thanks,
Mitchell

Ade answered 19/9, 2023 at 0:23 Comment(0)
P
0

Here's the Godot 4 equivalent:
file_menu.get_popup().id_pressed.connect(on_item_pressed)
https://docs.godotengine.org/en/4.0/getting_started/step_by_step/signals.html#connecting-a-signal-via-code

With a short callback function like that, you could also use a lambda function:
file_menu.get_popup().id_pressed.connect(func(): print("Hello"))

That tutorial is four years old? That was probably Godot 3.1. You may want to use an older version of Godot for the tutorial. With Godot 4 you'll likely run into many problems.

Pritchard answered 19/9, 2023 at 0:46 Comment(0)
A
0

Pritchard

Yep, I know it's old but I'm just using it as a reference. And updating anything that breaks to 4.1 syntax. I'm sure I'll likely break more things but this is really just a learning exercise so I'm fine with that for now. Having to update it to 4.1 is likely going to help with learning as well. Hopefully...

But thanks that solution works perfectly! Thanks

Ade answered 19/9, 2023 at 4:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.