Variable Types

As you just learned, variables can take the form of multiple containers like numbers, texts or lists. Let's see what we choose, based on what we need in our app.

In the previous activity — App, Stored and Cloud Variables — you learned about how we can store information in a variable. Next, we discover what type of information we should store, based on each variable type.


Numbers

In the above image, myNumber stores a number. This can be an integer or a decimal number. It can be positive or negative. Here are some examples of values and when we use them:

Type Value Example
Positive integer 129 The score, number of items in a list, age, number of clicks on a button, etc.
Positive / negative integer -12 Outdoor temperature, position of an element in a coordinate system, the score (if it can be negative), etc.
Number with decimals (positive / negative) 12.2 or -12.2 All of the above, when we need greater accuracy

Strings (Text Variables)

In the image above, myText stores a text. It can be the name or surname of the user, the city where she/ he lives, the text she/ he enters in a Text Input or any other type of text. Text variables can be combined to compose other variables that contain both texts. We do this using join (text1) (text2).

Boolean Variables

In the image above, the variables MyBooleanVar and MyBooleanVar2 remember only two types of values: TRUE or FALSE. For example, in a Tic-Tac-Toe game, you can use initialize (app) variable (isGameOver) to (FALSE) to remember if the game is over. After each move, check if one of the players is the winner or if there are no more vacancies on the game board, on which occasion you will assign the value TRUE to the variable.

List Variables

Lists are actually a set of variables. For example, the score for several rounds can be kept in a list. Thus, we have only one variable, Score, but we can effectively identify the score for each round. In the image above, there are two such examples: myListWithNumbers and myListWithTexts.