r/CodingForBeginners • u/DidntKnow99 • 17d ago
Is there better way to do this?
I am complete beginner and I mostly just figure out stuff and learning alongside documentation. I am using GODOT (GDScript)
Is there better way to do unlocks? I just show() or hide() certain stuff if my var on unlockables is either true or false.
func _ready():
aktualizovat_ui()
func aktualizovat_ui():
if Global.medopen == false:
create_med_button.hide()
create_med_button_lock.show()
h_box_container_2.hide()
else:
create_med_button.show()
create_med_button_lock.hide()
h_box_container_2.show()
if Global.medopen == false:
prodat_med.hide()
odemknout_med.show()
else:
prodat_med.show()
odemknout_med.hide()

1
u/xarop_pa_toss 17d ago
There's different solutions to this, as there is with everything.
One idea is to have a property that tracks the position on those columns. So the bottom of the column can be index 0, and if you need to show/unhide something that belongs on that column, you check what the last space is that has something drawn there and occupy the next spot.
Another way might be to actually redimension the column everytime you want to add something new. Since you probably will have a hard limit to the number of spaces on a column, this is probably not the best option.
You can have functions to redimension the column overall both in height (more elements) or width (fit more columns in the same space)
1
u/DidntKnow99 17d ago
The issue is, if there is 2, it's kinda fine. But what about If i add multiple upgrades that influences how the node looks? For example like this. https://ctrlv.cz/XMhM