Menu Button popup giving error
Asked Answered
M

6

0

`extends MenuButton

var popup

func ready():
popup = get_popup()
popup.add_item("item a")
popup.add_item("item b")
popup.add_item("item c")
popup.connect("id_pressed", self, "
on_id_pressed")

func _on_id_pressed(ID):
print(popup.get_item_text(ID), " pressed")`

any clue why line 10 is give this error?
E 0:00:01:0348 FileButton.gd:10 @ _ready(): Cannot connect to 'id_pressed': the provided callable is null.
<C++ Error> Condition "p_callable.is_null()" is true. Returning: ERR_INVALID_PARAMETER
<C++ Source> core/object/object.cpp:1257 @ connect()
<Stack Trace> FileButton.gd:10 @ _ready()

Morley answered 12/8, 2023 at 21:4 Comment(0)
A
0

The "callable" in the error message is "on_id_pressed", which doesn't exist.

Change:
popup.connect("id_pressed", self, "on_id_pressed")
to:
popup.connect("id_pressed", self, "_on_id_pressed")

Adenoidectomy answered 12/8, 2023 at 22:1 Comment(0)
M
0

thanks but it still appears to be giving the error

Morley answered 12/8, 2023 at 22:17 Comment(0)
A
0

Which version of Godot are you using?

Adenoidectomy answered 12/8, 2023 at 22:56 Comment(0)
M
0

Adenoidectomy 4.1.1 mono

Morley answered 12/8, 2023 at 23:24 Comment(0)
A
0

You're trying to use Godot 3 code in Godot 4.

Change line 10 to:
popup.id_pressed.connect(_on_id_pressed)

In the future, please mention your Godot version when asking for help with a problem. There have been many changes between 3 and 4.

Adenoidectomy answered 12/8, 2023 at 23:27 Comment(0)
M
0

Adenoidectomy thanks

Morley answered 12/8, 2023 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.