Help: How do you create Points + Levels system and save progress using TinyDB?

Hello,
I am building an app on MIT App Inventor and I need help designing a points + levels system.

Goal of the system:

User enters a daily water consumption limit (Example: 5 Liters)

Every day, the user enters the actual consumption

If the real consumption is less than the limit, the user earns points

When points reach a certain number (example: 100), the user levels up

What I need:

:white_check_mark: How to increase points
:white_check_mark: How to upgrade levels automatically
:white_check_mark: How to save both values using TinyDB so the user doesn’t lose progress

Example Logic:

If ActualConsumption < DailyLimit:
Points = Points + 10

If Points >= 100:
Level = Level + 1
Points = 0

TinyDB Tags I plan to use:

"DailyLimit"

"Points"

"Level"

If someone can show me example blocks or guide me on the best way to do this, I would really appreciate it.

Thanks!

Try a search

I tried and found some ideas that were somewhat similar, but I didn't understand them well and I didn't find a sufficient explanation.

All you need to save is the daily consumption.

The other quantities can be derived by counting forwards from the first day.

Save consumption under the yyyyMmdd date of that consumption.

Could you please explain further? I'm sorry if I'm bothering you.

image

Did you make the blocks yourself from the beginning, specifically for me? Thank you very much. I don't know what to say. + Is all I have to do is move these blocks to my place without adding anything, just as they are?

I left it to you to recreate the Designer components and the blocks.

That will help you to study the code.