Cooldown timer resets on screen change and doesn't restore attempts when time is up

Hello everyone,

I'm working on a virtual pet app using MIT App Inventor, and I’m currently building a cooldown system for a slot machine mini-game.

Here’s what I want it to do:

  • The player has 5 slot machine attempts.
  • Once those 5 attempts are used, a cooldown timer (e.g. 5 minutes) should start.
  • While the cooldown is active:
    • The timer should keep counting down, even if the user switches screens or closes the app.
    • A visible countdown should show how much time is left.
    • After the cooldown ends, the attempts should automatically reset to 5, and the countdown should disappear.

Current issues I’m facing:

  1. When I leave and return to the screen, the countdown resets instead of continuing from where it left off.
  2. The attempts don’t get restored automatically when the cooldown reaches zero.
  3. I do store the cooldown start time (cooldownStartTime) in TinyDB, but it seems like I’m not using it properly when checking how much time has passed.
  4. When the countdown reaches zero, the slot attempts don’t reset — instead, the value keeps decreasing into negative numbers, which shouldn't happen. Attempts should stop at 0 and reset to 5 after the cooldown finishes.

What I’ve done so far:

  • I save cooldownStartTime using the clock block: Clock1.SystemTime.
  • On screen initialize, I retrieve the value and try to calculate the remaining seconds.
  • I use a second clock to update a label every second with the time left.
  • I save and retrieve remainingSlotAttempts and remainingCooldownSeconds from TinyDB.

What I think I'm missing:

  • A proper way to check if the cooldown is active when loading the screen (cooldownStartTime ≠ 0) and calculate the remaining time correctly.
  • The logic to reset the attempt count when the cooldown reaches 0.
  • Clearing or resetting cooldownStartTime after the cooldown is over.

I’m on a deadline:

This project is part of my university coursework, and I need to turn it in tonight before midnight, so any quick help would be massively appreciated!

If needed, I can post screenshots of my current blocks (I’ve already been using 2 clocks: one for game logic and one for the countdown display).

Thanks in advance!

Snark_tumascotapasivoagresiva_1 (5).aia (902.8 KB)

I close and unlist this. Don't double post.