Hi, its me again.
I’m working on a virtual pet app in MIT App Inventor, where the user takes care of a sarcastic creature named Snark. I use a global variable called AfectoMascota
(pet affection), and I store its value using TinyDB so the affection level can persist across screens. Everything works fine on the older screens — I can modify the affection, store it, and it loads correctly when I return. However, I recently added a new screen that includes a mini-game (a slot machine), and in this screen the affection bar doesn't update properly, even though I’m using the same logic as in the other screens.
Here’s what I do:
On affection change:
plaintext
call TinyDB1.StoreValue
tag: "AfectoMascota"
valueToStore: global AfectoMascota
In Screen.Initialize
of the new screen:
plaintext
set global AfectoMascota to call TinyDB1.GetValue
tag: "AfectoMascota"
valueIfTagNotThere: 0
call UpdateAffectionBar
The UpdateAffectionBar
procedure is supposed to adjust a label’s width and color to reflect the affection level. But it doesn’t show any change when entering the screen, even after I modify the value in another one.
Snark_tumascotapasivoagresiva_1 (2).aia (796.1 KB)
Could there be something I'm missing when loading the value on this new screen? Or is there something different I should be doing when using TinyDB with new screens?