Godot Version
V4
Question
I’m trying to add a drop down button to change the seed equipped for planting based on the players “owned_seeds” dictionary. It receives the “all_crop_data” info from a global array with all crop resources in it.
I use a loop to have it add all items to the drop down menu, which goes fine . The problem is I either get duplicated items, or the menu confuses the first and second item. I’ve tried multiple ways of clearing the items but it always ends in duplicates or confused items.
I have it set to print the index it receives from the options button which is correct, but the wrong seed information gets passed. Zero should be pulling Chamomile from the array, but it pulls Lavender instead->
0
1
(res://Assets/Resources/Plants/Lavendar.tres):<Resource#-9223371976070920588>
1
(res://Assets/Resources/Plants/Lavendar.tres):<Resource#-9223371976070920588>
2
(res://Assets/Resources/Plants/Basil.tres):<Resource#-9223371975869594010>
1
(res://Assets/Resources/Plants/Lavendar.tres):<Resource#-9223371976070920588>
func _on_options_button_down() -> void:
for i in Global.owned_seeds:
var seed_name = i.display_name
options.add_item(seed_name)
func _on_options_item_selected(index: int) -> void:
print(index)
var crop_number = index
set_seed(crop_number)
func set_seed(index:int):
var selected:CropData = Global.all_crop_data[index]
seed_button.seed_type.text = selected.display_name
seed_button.seed = selected
print (selected)