**\[Help] Affection bar not updating correctly in new screen using TinyDB**

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?

The cause is, you should maintain same name space for tinydb. In screen 1 it was written as tinydb1 but in screen2 it was changed. If so you cannot recover the saved value from tinydb. You should maintain the same namespace



Screen 1 value cannot be read in 2 and 3 but 2 and 3 can be read

1 Like

Oh, thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.