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:
- When I leave and return to the screen, the countdown resets instead of continuing from where it left off.
- The attempts don’t get restored automatically when the cooldown reaches zero.
- 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. - 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
cooldownStartTimeusing 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
remainingSlotAttemptsandremainingCooldownSecondsfrom 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
cooldownStartTimeafter 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)