Problem with cooldown timer not firing in my slot machine game

Hi MIT App Inventor community,

I'm developing a slot machine-style mini-game in App Inventor that includes a cooldown system after a limited number of attempts. I'm using TinyDB to store:

  • The number of remaining attempts (remainingSlotAttempts)
  • The cooldown time in seconds (remainingCooldownSeconds)

The Goal

Once the player uses up all 5 attempts, a 300-second (5-minute) cooldown should start. During this time, a countdown is displayed using a Clock component (RelojEspera). After the countdown finishes, the 5 attempts are restored automatically.

The Issue

Even though:

  • The global Cooldown value is saved and updated correctly,
  • RelojEspera.TimerEnabled is set to true,
  • The block when RelojEspera.Timer exists in the project,

… the timer event never fires, and the countdown does not update on screen.

:mag: What I've tried so far

  • Confirmed that RelojEspera is on the current screen.
  • Made sure its TimerInterval is set to 1000 ms.
  • Placed alerts inside the Timer event block to confirm if it runs (it doesn't).
  • Tried re-enabling the timer in multiple ways after setting the cooldown value.
  • Checked for any other block that could be disabling the timer β€” found none.

Key Blocks

I've attached screenshots of the relevant blocks in this thread.



Question

What could prevent a timer from firing even if it’s enabled and its interval is set properly? Could this be related to execution order or how App Inventor handles enabling timers?

Snark_tumascotapasivoagresiva_1_1 (1).aia (980.1 KB)

Yes. I think i have set it. I tested with limited time of 5 in cooldown when the user used up all of his attempts. And as per the code now it triggers . Once the cooldown finish again the game starts, meanwhile if the user reopens the open cooldomw begins from where he left. But remember if the user clears data then everything wil reset.

Modified code

image
image

Snark_tumascotapasivoagresiva_1_1_1.aia (980.1 KB)

1 Like

Thanks! but now the timer is displayed, but if I leave the screen and come back, it is no longer displayed.

add this block and try now

But this logic says, user either need to wait compulsorily 5 min to play and even if he comeback after few hours. instead you do alter the logic such a way that when the user lost his 5 attempts get current time in milli and add 300000 with it and save it as end time. and find the difference between this saved time with current time. if the difference goes in negative even if he come back after few min or hr, clears the end time with zero. suppose if h come to ap less than 5 min from the last click timer, then the difference will give you in positive value and let the user to wait until the difference goes less than 100

Oh, oki, i gonna try that, but if it's not too much trouble, could you also help me with that?

It's easier if you store:

  • The cooldown end (Clock1.SystemTime)
  • remaining number of plays per current session

Sample runs, beginning with a 5 minute cooldown and 5 plays:
sample run V2

Cooldown happens in real time, regardless of if the app or scren is running.

Resumption near end of cooldown (I got impatient and changed the cooldown time to 1 minute, but the 5 minute cool down was still running.)
sample run V3

I have the two constants in CAPITALIZED global variable constants, to make them easier to customize.


(That's 5 minutes, the long way)

The Designer:

  • the mm:ss cooldown Label
  • the remaining play count before cooldown starts
  • the Play button

The 1 second always running Clock Timer:

The Clock Timer has been given the responsibilities:

  • Keeping the displayed cooldown time up to date
  • watching for a disabled Play Button whose cooldown limit has been reached or passed, and reviving it with a fresh Play count to begin its new play cycle.

Notice that I use NO global variables, working only off TinyDB and the display Labels.
This avoids confusion as to where the one and only truth resides.

The Play Button:

The Play button decreases its remaining count each time it is clicked.
When it runs out of remaining Plays, it disables itself.

Notice how the Play Button's dying act after it discovers it has been disabled is to set up the end of cooldown time in TinyDB, to let the Clock Timer revive it at the appointed time.

Some time formatting procedures:

Formatting for output and guarding against overdue cooldown end:

Getting remaining cooldown seconds (possibly zero or negative if out of cooldown.)

All the blocks, and the aia:

cooldown.aia (4.0 KB)