Working With Variables
Published on February 6, 2022
Variables are pieces of data you can temporarily store. Unlike TinyDB, even if you set the variable to something in the middle of the program, if the user exits and opens the app again, the value is set the the original value.
There are global and local variables. Global variables are variables that can be accessed any where in the screen, but local variables can only be accessed in a specific part of the program. Parameters are a type of local variables.
For more information, read this MIT App Inventor community thread.
π·οΈ Tags: #tutorials-and-guides
To create a global variable, use this.
You can change the name of the variable by clicking on 'name'. The socket of the variable is the value that the program will first set the variable. If you did not plug in anything, the default value is 0.
Global variables support components, texts, numbers, colors, lists, booleans, dictionaries and helper blocks, but do not support other variables or procedures. This is because another variable or procedure must not be in a definition.
If you hover over a variable, you will see it has a get and set block to get and set the value of the variable. You can drag them out from there, or drag one out from the Built-in > Variables drawer.
If you did not set the name of a variable properly, an error will occur.
To create a local variable, use one of these, depending on your needs.
Local variables are variables that can only be accessed among the mutators. To create another local variable, click on the blue settings icon and drag the 'name x' block into the mutator.
What type of text does variable names accept?
From this post.
βοΈ Contain @, $, _, ?
βοΈ Contain English alphabets
βοΈ Contain numbers that are not at the start of variables
βοΈ Contain Chinese, Greek, Arabic characters, Γ, Γ, Γ
βοΈ Contain Unicode characters or emojis.
βοΈ Start with zero-whitespace Unicode character, then numbers
β Contain !, #, ^, &, *, (, ), =, +, /, , , . , :.
β Start with a number
Β© Gordon Lu π§ E-mail π¬ Message π Phone call