Global variables

Global variables - an object intended for transferring variables between scenes within one project. That is, if you need to set some variable value and save it when moving to another scene, this object is for you! Global variables can include values that will be determined by a key. The number of keys is not limited in any way. Key values are divided into three types: string, number, and boolean value. Let's consider the properties of the object
Inspector
There are no settings for this object in scene editing mode
Blockly
Variables
Returns the specified global variable
Logic
Check if the selected global variable contains a key
Actions

Set the key string for the selected global variable

Set the number for the key for the selected global variable

Set a Boolean true/false value for the key

Delete the key value of the selected variable

Remove all keys from the selected variable
Functions

Returns the current value of the specified key of the selected variable
Example
Let's look at a case where we need to move variables from one scene to another
Creation
- Create a project
- Let's create two scenes
- On the first one, let's place two buttons and sign them, that each of them will perform
- The first button will assign some values to the global variable
- The second takes us to a different scene
- Let's go to the logic editor and set up the logic in the first scene
- The following logic will be executed when you press the button
- Assign the text for key 1
- Assign a number to key 2
- Assign a Boolean value to key 3
- Assign the values of the three previously specified keys to the text
- For the second button
- Transition to the second scene
- The following logic will be executed when you press the button
- Let's go to the editing of the second scene and place three buttons with explanatory text
- The first button will show us that the variables have been migrated correctly
- The second will remove the value with key 1 from the global variable
- The third will delete all the keys
- Let's go to the logic editor of the second scene and configure the buttons
- When you click on the first button, the text will be replaced by the global variables carried over from the previous scene
- When you click on the second button, the text will be replaced by the global variables carried over from the previous scene
- Delete a value with key 1 from a global variable
- Let's check if the global variable does not contain key 1, then the text that key 1 is not in the variable + all remaining keys will be displayed
- else, displaying all keys
- When the third button is pressed, we will delete all keys from the variable
- When you click on the first button, the text will be replaced by the global variables carried over from the previous scene
Testing
- Let's start the project
- On the first scene, click on the first button, we will see that the text panel is assigned the newly created values of the three keys
- When we are sure that everything is working, we press the second button and move to another scene
- Click on the first button, check that the variables have been migrated.
- Press the second button to delete the first key
- And now let's check the block of deleting all variables
As you can see, the third text panel has become empty because all values of all keys have been deleted, hence there is nothing to output!