Problem with variables

Hello, I'm new to MIT App Inventor and I need help with something, my problem is that whenever I press upgrade it doesn't do anything. It should take away the points, change the upgrade price... but it just isn't doing this. Earlier it worked but then I added some more things to saved between screens using TinyDB and now it doesn't work. When I got to Screen2 (Upgrades) then the points do transfer properly from Screen 1 to Screen 2 but I can't upgrade, Can somebody please help me?


Pressing the Upgrade button only changes the contents of the tinydb tags, it doesn't change anything you can see in the app - e.g. textboxes or labels that hold the information. So it will seem like nothing changes until you get to Screen "Upgrades" when you will see the Points textbox/label set to tinydb tag Points.

Thanks for the reply, so what do I have to change to make this work, cause from what you said i can't really tell what do I have to change, sorry i'm a newbie.

Please explain again, in more detail, exactly what you expect to happen when you press the Upgrade button, then perhaps I will understand what it is you want....

When I press it I want it to change the points to points - price (50) then change the price to 2.7 the previous price, and add 1 to the workers upgrades owned text.

On the screenshot of screen 2 check the middle blocks

Then set these things from the tinydb tags on Screen (Upgrades) initialisation, like you do with the Points?

Do you really need multiple screens ?

Use different screens wisely

If you decided to use different screens, then you should switch them correctly, else you will run out of memory after a while...      
The recommended method of switching screens in App Inventor
(Thanks Taifun)
Also see demo: multiscreen.aia

But i want it to happen after i click the button and if the number of points is the same or higher than the price of the upgrade. It worked fine earlier but after i saved the variables data between screens with tinydb it doesnt wanna work.

What about your Upgrade_Workers button on the Upgrades screen. Isn't that doing what you want ?

That's what my problem is about, it doesn't work at all. When I click it nothing happens when I was trying to see what is wrong with it, im pretty sure it is something with the if statement cause its not able to get pass through it and do the "then", its just stuck at the "if" statement for no reason. Cause the points label shows the correct number and when its over 50 then it should work but it doesnt for some reason

Ah, now we are getting somewhere, you have explained :wink:

Try this instead....


Note, it will only change things if it meets the condition. You may need to add the else section to do something if it doesn't meet the condition, otherwise nothing happens.....

Sorry, and thanks ill try that tomorrow and tell you if it worked.

Still it doesn't work and nothing is happening even tho I have 127 points. : (

I added this to see if it even detects that the number of points is higher than the upgrade price variable but it doesnt chnage the text to "worked" so it doesnt work. I don't know why cause last time I was doing the same thing but to show the price and it showed the correct price so upgrade price variable is set to 50 so I really dont know whats wrong with it.

Now I added an else statement and it did show "doesnt work" so it doesn't meet the condition somehow idk why

It will be faster to diagnose the problem on its own skin :grin:. Send the .aia file.

How do I send the .aia file?

In menu Projects, click "Export selected project (aia) to my compuuter."

And such a small note for beginners. Before you start building complex applications, start learning from simple projects, and most importantly from learning the appinventor interface, because that's the basics.

Thanks, here it is:

Business_Tycoon.aia (7.1 KB)

Should it work like this?
Business_Tycoon (1).aia (7.4 KB)

The problem is that you load the data from tinyDb into a variable, but you do math on the labels. Do math operations on variables and use labels only to display the results.