Hi dear community.
I'm trying to iterate a foreach loop using a for in like in the next example. I need to get the index to multiply the button size and spawn it in the correct spot.
func create_buttons():
delete_buttons()
for i, unit in selected_units: //i gives me an error
if not buttons.has(unit.name):
var but = button.instance()
but.connect_me(self, unit.name)
var offset = 64
but.rect_position = Vector2(buttons.size() * i + offset , $UI/NinePatchRect.rect_size / 2)
$UI/NinePatchRect.add_child(but)
buttons.append(but.name)
I know i can create an var outside the loop and the incrementate but thats ugly.
I'm new in gdscript and python. Any kind of help will be appreciated.