Someone helped me make this code and I can't seem to implement something I want to add

Basically, this code shuffles between an array of timers (there are 5) and picks a timer that hasn’t started yet. These timers, upon completion, should disable the conditional button that is linked to it (there are 12 buttons). I want to add that if a timer ends, it disables the corresponding conditional button. If someone could help, this would be greatly appreciated.

    ShuffleTimer(SelectedButton:conditional_button_device):void = 
        if (UnusedTimers.Length > 0):
            set UnusedTimers = Shuffle(Timers)
    
        if (NextTimer := UnusedTimers[0]):
            NextTimer.Start()

        set UnusedTimers = for:
            Index -> Timer : UnusedTimers
            Index <> 0
        do:
            Timer


    TimeIsDone(Agent:?agent):void={}

The code below compiles correctly, but I didn’t test…

# function...
DisableButtonAfter(Delay: float, SelectedButton: conditional_button_device)<suspends>: void =
    Print("in DisableButtonAfter")
    Sleep(Delay)
    SelectedButton.Disable()

# test function...
ButtonClicked(Timer: timer_device, SelectedButton: conditional_button_device): void=
    Print("ButtonClicked")
    var Delay: float = Timer.GetActiveDuration()
    spawn { DisableButtonAfter(Delay, SelectedButton) }

I see what you mean but that’s not exactly it, basically in my code, it shuffles between 5 timers and the issue is that I want the running timer to disable the button upon SuccessEvent

You could then listen to the timer’s Sucess event, but then keeping track of which button to disable would be a pain. Do you know the timer will succeed once the button is pressed (in which case waiting for the timer’s duration would work); or could the timer be paused, in which case you are stuck with listening to the success event.