Change dynamic panel state if no action taken after 10 seconds

I’m struggling with how to do this. I have a series of 5 steps that needs to be completed by the user. Each step is a separate state in a dynamic panel. When the user gets to the 3rd step, I need a 10-second timer. If the user presses a button before the timer is up, they advance to step 4. If they do not press the button within 10 seconds, they go back to state 3.
The issue I am having is that when I set a timer using this method (Countdown Timer with Timestamped Messages), the user presses the button on step 3 and goes to step 4, but the timer still counts down and suddenly they are taken from step 4 to state 3 (the timer still runs even though they clicked the button to advance).
Any suggestions on other ways to accomplish this requirement?

It will help greatly if you could post your .rp file.

Basically, when you advance to state 4 in your dynamic panel (dp), you need to either stop the timer or test if the dp is still on state 3, and only execute the timer code if on state 3 (or perhaps earlier) and not on state 4. The method in the thread above does not look like it provides a way to stop the timer, so you’d need to add a condition when the timer expires–something like “if state of MyDynamicPanel is State 3” then “set MyDynamic panel to State 2”.

I will assume you mean “go back to state 2” --the previous state.

A better approach, in my opinion, is to create a timer using a dynamic panel with two states. To start the timer, set the dp to change to the Next state, wrap and repeat. You can set the timer resolution in milliseconds (e.g., every 1000 ms for once per second, every 100 ms for once every 10th of a second, etc.) and it will faithfully change states until its text reaches 0 (zero). It is a more reliable and flexible timing method than a loop that has a “wait 1000 ms” statement in it. It can also be stopped at any point (by “set timerPanel to stop repeating” --where “stop repeating” is a state you can choose in the “Set Panel State” action). The timer can be reset on the fly simply by setting its text to a number greater than zero. You don’t have to wait for the timer to finish in order to reuse it. Also, it is self-contained and doesn’t require any global variables (but they can be added if you need to share the time across pages for any reason.)

See this example of a timer:
dpTimer.rp (144.5 KB)

On Page 1, I’ve hidden the timer stuff (actually it will hide itself with OnLoad) and added a dp with 5 states and a Next button to move to the next state. When the dp changes state to State 3, it starts the timer. On the third state, if you do not press the Next button within 10 seconds, the timer will expire and change the dp to the previous state (State 2).

There is a countdown timer on state 3 as well. It is updated each time the timer dp (named “Timer Panel”) changes state. Obviously, you don’t need to keep this if it’s not needed.

1 Like

Thank you mbc66. Yesterday I started working with a timer using a dynamic panel set up to advance to the next state, wrap and repeat, but your example is a bit more robust than what I was working with. Thanks for the thorough explanation, super helpful and I’m sure I’ll refer back to it in the future.

Hi heatherg,

I’ve had to do this sort of thing before.

I stripped down to a simple sample that shows how to do a timed step without using global variables.
Enter any text to enable the next button at each step. After entering text at step 3, it starts and shows the timeout occurring.

See it live at https://79yi45.axshare.com/#g=1&p=home

The RP file is here: simple timer.rp (113.5 KB)

Let me know if that fixes it for you.

Cheers,

-Bill

1 Like

@SifuDynamic,

You show the same timer method that @heatherg described, and it suffers from the same basic issue: the timer can’t be stopped externally, so it always counts down to zero and does its thing–erasing the input_3 text field, even if the user clicks the NEXT button in time. So, if I wanted to do something meaningful with the text a user enters on each step, I couldn’t do it for step 3 because it always gets erased after 10 seconds. Or, if I need to go back a step on the timer expiration, as @heatherg needs to, it would still happen regardless of what the user does. (Unless of course, I add more conditions to the timer or the NEXT button.)

Also, if I need a timer on each step, I would need to replicate your timer widgets instead of reusing the same timer, starting, stopping and resetting as needed.

@mbc66,

Sorry, it’s fixed now. Thanks for catching that :slight_smile: When I stripped it down from my client work, I missed the line to stop the timer. I fixed it now and added a back button so you can see that the timer stops and the field is not erased if you hit ‘NEXT’ on step 3.

See the correction live at https://79yi45.axshare.com/#g=1&p=home

Here’s the corrected RP file: simple timer (corrected).rp (119.0 KB)

Let me know if that works better.

-Bill

2 Likes