Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Documentation on Signal item_selected from OptionButton #36803

Closed
viniciusaportela opened this issue Mar 5, 2020 · 2 comments · Fixed by #37303
Closed

Wrong Documentation on Signal item_selected from OptionButton #36803

viniciusaportela opened this issue Mar 5, 2020 · 2 comments · Fixed by #37303

Comments

@viniciusaportela
Copy link

Godot version:
3.2.stable

OS/device including version:
Windows 10 18363

Issue description:
On docs show that the signal item_selected from OptionButton has the ID parameter when it actually the Index, that's a small thing but it really confused me at first that passed over 30 min trying to figure out what was wrong (cause I used the id to be the same to index)

Steps to reproduce:

  1. Create the nodes

image

  1. Create the items

image

  1. Connect item_select
$Option.connect("item_selected", self, 'on_option_changed')
  1. Start Clicking

Minimal reproduction project:

extends Control

func _ready():
	$Option.connect("item_selected", self, 'on_option_changed')
	$Option.remove_item(0)

func on_option_changed(idx):
	print('item changed')
	print(idx)

Selecting from bottom to top it returns:

image

Not 30, 20, 10 as expected

@aaronfranke
Copy link
Member

Yes, I can confirm that "id" should be changed to "index" in option_button.cpp line 344, but I don't know if the same should be done for item_focused.

However, while testing, I encountered really weird behavior.

Screenshot from 2020-03-05 02-58-41

Code:

func on_option_changed(idx):
	print('item changed')
	print(idx)
	print($Option.get_selected_id())
	print($Option.get_item_id(idx))
	print($Option.get_item_index($Option.get_item_id(idx)))

Output:

item changed
1
20
20
1
item changed
0
10
10
0

Seems that the index in the item list editor does not match up with the index at runtime. The item with an ID of 20 has an index of 2 in the editor, but when selected, it has an index of 1. I'm also unable to reselect "Item 0" with an ID of 0.

@zak-grumbles
Copy link
Contributor

Submitted merge request #37303 as a fix for this, although the changes only cover fixing documentation and the ADD_SIGNAL call in code and do not address the editor-runtime index mismatch.

@akien-mga akien-mga added this to the 4.0 milestone Apr 10, 2020
zak-grumbles added a commit to zak-grumbles/godot that referenced this issue Apr 11, 2020
* item_selected and item_focused docs incorrectly had 'id' as the parameter. Changed to
'index'.
* Fix parameter name in ADD_SIGNAL callin code.
akien-mga added a commit that referenced this issue Apr 11, 2020
…ted-docs

Fix OptionButton item_selected docs #36803
akien-mga pushed a commit to akien-mga/godot that referenced this issue Apr 16, 2020
* item_selected and item_focused docs incorrectly had 'id' as the parameter. Changed to
'index'.
* Fix parameter name in ADD_SIGNAL callin code.

(cherry picked from commit a8de034)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants