This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I am trying to use an ItemList to create a clickable text menu. I could not find any tutorial on the subject, nor easy and clear explanation, so I really expected it to be as simple a using a list of buttons, but I think I was wrong.
My ItemList has two items: item01 and item02 and was set to send an item_selected(index int) signal

I am trying to get at least a print command working after item01 or item02 gets selected.
So far I tried things similar to:

func _on_ItemList_item_selected(index):
     if $ItemList.is_selected(1) = true:
          print("Item 01 selected")

but nothing works.

So, I have two questions.
1. How to detect that item01 is selected/clicked in
func _on_ItemList_item_selected(index):?
2. Why is it so different from the idea of button pressing detection etc. (at least it looks like that at first)? ;)

in Engine by (722 points)
edited by

Your example code has a missing = in the condition. It has if value1 = value2 instead of if value1 == value2

Thanks Rodrigo Matos. You are right. That was the problem!

1 Answer

+1 vote

I cannot reproduce your problem, this works fine:

extends ItemList

func _ready():
    add_item("item01")
    add_item("item02")

func _on_ItemList_item_selected(index):
     if is_selected(0):
          print("item01 selected")
     if is_selected(1):
          print("item02 selected")

Can you provide an example project with the problem?

by (10,634 points)

Thanks for the answer.
My problem was the typo I did and = instead of ==, so Rodrigos Matos who commented was right and actually gave me the answer as well.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.