Hi again guys! I'm making a virtual pet game in App Inventor, and I’ve added a mini-game (a slot machine) where the user only gets 5 plays, and then must wait a cooldown period (e.g., 5 minutes) before playing again.
The logic works fine during a single session, but the problem happens when the user clicks a "Return" button to go back to the main screen, and later returns to the slot machine screen. The counter resets and lets them play again immediately — which is not what I want.
What I tried:
- When the user clicks the Return button, I save the current time using:
plaintext
CopiarEditar
call TinyDB1.StoreValue
tag: "TiempoGuardado"
valueToStore: Clock1.Now
- Then I open the main screen:
plaintext
CopiarEditar
open another screen: Screen2
I also retrieve the time on the slot screen's Screen.Initialize
event:
plaintext
CopiarEditar
set global TiempoGuardado to call TinyDB1.GetValue
tag: "TiempoGuardado"
valueIfTagNotThere: 0
But when I test it, the time value doesn’t seem to update or get compared correctly. The play counter gets reset, as if no waiting time was enforced.
What I need:
I want the screen to remember the time of the last play session and only reset the number of plays if the cooldown time has passed.
Has anyone done something like this before? Could I be missing something in how TinyDB works across screens?
Thanks in advance for your help!
Snark_tumascotapasivoagresiva_1 (3).aia (796.4 KB)