Setting a timer from a button press event, not a submit click

I hope this isn’t too naive as I’m on the learning curve for CL … .

I have four buttons that I can detect fine, but I’d like to kick off a timer based on selecting any of the four buttons. It’s set up now to start a timer when the submit button is clicked. In fact, I don’t want the submit button at all.

I saved one slide here: Button, Button, who clicked the button? • Activity Builder by Desmos


I would probably use the ticker to control the timer, and use the a_nimation toggle to control when it runs.

So for instance, in the ticker: {a_nimation=1:T->T+0.05,T->0}

Then in the CL you can have
number(`a_{nimation}`) = when ( PL.isSelected(1) or PL.isSelected(2) or PL.isSelected(3) or PL.isSelected(4) ) 1 otherwise 0

I haven’t tested this but this or a variation thereof should work, I think!


Thanks. That works, but I can’t see how to reset T each time a button is pressed other than Submit or unselecting and then reselecting.

I’m also trying a version by replacing the Multiple Choice Component with four separate buttons and comparing their timeSincePress values, but that not working at all. Debugging is a nightmare. Is there a way to see the values of variables in CL?


Can’t see the values in the CL itself, but you can always send them to a note or table. That’s what I do to debug sometimes.

1 Like

Thanks. I used a now hidden table to get the 4-buttons version to work.

Great that you got it working.

Just as a future idea:

I would potentially use a “latch” variable - so for instance if you had s_el representing the chosen item 1-4 and p_sel as the “latch”, then your ticker could also include:


This way, if the selection changes, it will reset T to zero and update p_sel to match.

Again, not tested this specifically but think it should work as you expect.

1 Like

Thanks. Interesting. I have to think about whether to recode.