How to reference several UI elements when clicking a certain button to avoid code duplication?

Hi,

I got several labels and timers in my UI, e.g. label0 and timer0, label1 and timer1. Each of these pairs have a button (button0, button1), I got 10 of these in total.

The user is supposed to press the first button and it will change the label and start the timer. Then he is supposed to press the next button. Then the same will happen to the next label and timer and so on.

I’ve been searching here and on the web for days but cannot wrap my head around how to avoid code duplication and instead reference thes label and timer elements.
kodular

In the image above this would work but I would have to duplicate this 10 times. I was thinking of using “when any Button.Click” but then I have no idea how to reference the label and timer elements of that respective button that was pressed. I can only reference which button was clicked this way and I don’t think using 10 “if button X was clicked then change label and timer X” is any better.

What is the right approach to use here?

1 Like

What about using only 1 button, 1 label and 1 clock component and adjusting everything else (for example the text to display on the label or button) programmatically? You can have a global variable to indicate, in which step you are in…

You might wabt to explain your logic more in detail… what is the difference between timer 1, 2 and 3?

Taifun