making a dropdown/option menu

ItsColdItsCold Posts: 8Member

hello, so uh, im trying to make a dropdown menu for my game and using this video here

https://godotdevelopers.org/forum/discussion/17966/beginner-optionbutton-dropdown-interaction-gui-in-godot-engine/p1

as reference.
But it gave me an invalid call.nonexistent function error.
here's the code :

extends Control

export (NodePath) var DropDown_path
onready var DropDown = get_node(DropDown_path)

func _ready():
add_items()

add item to drop down menu

func add_items():
DropDown.add_items("option 1")
DropDown.add_items("option 2")
DropDown.add_items("option 3")
DropDown.add_items("option 4")

from my understanding godot doesn't recognize the add_items function but it works just fine on the video,
maybe someone can give me a bit of insight ?

thank you a lot.

Answers

  • kryzmakkryzmak Posts: 67Member
    edited December 4

    Are you sure, that DropDown in fact is the PopupMenu node and not the MenuButton? If it is the MenuButton you first have to call the get_popup() function, so it could be:

    onready var DropDown = get_node(DropDown_path)
    
    func _ready():
        DropDown = DropDown.get_popup()
    
  • ItsColdItsCold Posts: 8Member
    Answer ✓

    @kryzmak said:
    Are you sure, that DropDown in fact is the PopupMenu node and not the MenuButton? If it is the MenuButton you first have to call the get_popup() function, so it could be:

    onready var DropDown = get_node(DropDown_path)
    
    func _ready():
      DropDown = DropDown.get_popup()
    

    DropDown is an OptionButton node, made sure of it.
    And it works just fine in the vids

  • MegalomaniakMegalomaniak Posts: 1,001Admin
    edited December 4

    That post is from 2016 so chances are high it's using godot 1.x or 2.x

    Are you using godot 3.0.x perhaps?

  • kryzmakkryzmak Posts: 67Member

    Ok, this is a typo. Method is called add_item() and not add_items()

  • ItsColdItsCold Posts: 8Member

    @Megalomaniak said:
    That post is from 2016 so chances are high it's using godot 1.x or 2.x

    Are you using godot 3.0.x perhaps?

    uh yes, i'm using godot 3.
    kinda difficult to find a suitable godot 3 guide around

    @kryzmak said:
    Ok, this is a typo. Method is called add_item() and not add_items()

    uh no, it is add_items()

  • kryzmakkryzmak Posts: 67Member

    Not in my Godot Version (3.0.6)

  • ItsColdItsCold Posts: 8Member

    @kryzmak said:
    Not in my Godot Version (3.0.6)

    silly me, the code is on a control node which is the parent of the dropdown node,
    no wonder i can't use add_item().

Sign In or Register to comment.