Countdown timer issue

Hi, could anybody help me on this.

I try to create an email verification function. Upon clicking on “Send” button, it will disabled and countdown 5s until 0s before it is enabled to click resend again. Here comes the problem, if i enter the same case to RESEND button as in SEND button “is greater than or equals” to stop the countdown at 0s, i can’t even click the RESEND button… I tried to make “is less than or equals”, the RESEND button can click but the countdown doesn’t stop at zero :frowning:

I want to make this function keep able to click resend after each countdown to zero.

countdownissue.rp (119.7 KB)

image image image

Timers are tricky… In general, it is more reliable to use a dedicated dynamic panel with at least two states as a “timer function”; use the “Set Panel State to Next, wrap, repeat every N ms”. But in your case, since the user cannot click the Send button again it should and does appear to work well enough by recursively “clicking itself again” with the Fire Event action.

You are on the right track and close to a working solution, but I found three basic issues with your interaction logic:

  1. You don’t need a case for the Click or Tap event of “EV_resend button” because the first thing you do in the “EV_send button” is to disable “EV_resend button” until 5 seconds have elapsed and the global variable, “verification_countdown” value is less than zero (then you enable it.) So, if “verification_countdown” is greater than or equal to zero, nothing will happen if “EV_resend button” is clicked–no event will be triggered since it is disabled. But in Case 1 you state “If value of verification_countdown is greater than or equals 0” --which would never be true if “EV_resend button” were enabled.

  2. You never reset the value of “verification_countdown” when your timer expires, so it is impossible to “count it down” again. It is best to reset the value in Case 2 of “EV_send button” (which is enacted when the value of “verification_countdown” is less than zero, and thus Case 1 evaluates to false.)

  3. You don’t need to set up a separate timer in the “EV_resend button” code, because you want it to do the exact same thing as Case 1 of “EV_send button” already does. So, all you really need to do in the Click or Tap event of “EV_resend button” is to trigger a click of “EV_send button” with “Fire Event EV_send button fire Click or Tap”.

See this updated file where I duplicated the Email verification page and applied these fixes. One small thing to note is the timer duration is actually 6 seconds because you start at 5 and decrease “verification_countdown” to “less than 0” (meaning it stops at value of “-1”) --you can adjust this by either starting at “verification_countdown” = 4 or setting the Case 1 condition to “greater than 0”.

countdownissue.rp (154.7 KB)

1 Like

Thank you so much @mbc66. I learned something from you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.