Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gdevelop5:all-features:variables [2021/04/19 17:09]
midhil457
gdevelop5:all-features:variables [2021/11/22 23:06] (current)
Line 43: Line 43:
 **Modify the boolean value** **Modify the boolean value**
  
-You can set the boolean value to True or False.+You can set the boolean value to `"true"or `"false"`.
  
 **Toggle the boolean value** **Toggle the boolean value**
Line 53: Line 53:
 **Compare the boolean value** **Compare the boolean value**
  
-You can check if the boolean value is True or False+You can check if the boolean value is `"true"or `"false"`.
  
 To compare a boolean to another value, text or boolean, you can use **Compare the text of a variable**. To compare a boolean to another value, text or boolean, you can use **Compare the text of a variable**.
Line 71: Line 71:
 <note warning>Don't try to use text as an array variable index, it will return the variable at index 0!</note> <note warning>Don't try to use text as an array variable index, it will return the variable at index 0!</note>
  
-#### Accessing child variables+### Accessing child variables
  
 Variables that exist within a collection variable are known as _child variables_.  Variables that exist within a collection variable are known as _child variables_. 
Line 78: Line 78:
 ``` ```
 <parent_variable>.<child_variable> <parent_variable>.<child_variable>
 +```
 +Assume we have this structure:
 +
 +{{ :gdevelop5:all-features:variable_strucure_with_values.png?nolink |}}
 +
 +To get the value `123` we can write the following expression
 +
 +```
 +GlobalVariable(players.player1.level1score)
 ``` ```
  
Line 86: Line 95:
 <note>Collection variables can contain other collection variables. This makes it possible to store complex data in a single variable. Just be careful the data doesn't become too difficult to manage.</note> <note>Collection variables can contain other collection variables. This makes it possible to store complex data in a single variable. Just be careful the data doesn't become too difficult to manage.</note>
  
-#### Accessing child variables dynamically+### Accessing child variables dynamically
  
 You can use expressions to dynamically access child variables. You can use expressions to dynamically access child variables.
Line 94: Line 103:
 ``` ```
 PlayerScore[“Level”+ToString(Variable(CurrentLevel))] PlayerScore[“Level”+ToString(Variable(CurrentLevel))]
 +```
 +Whatever is inside the square brackets will be interpreted as the name of the child.
 +
 +If you need to use a variable to define part of the child path, all the subsequent children in the path will need to be in square brackets as well.   In the above example if you wanted to address a child at PlayerScore.Level1.enemies.killbonus but still define the level dynamically, it would look like this:
 +
 +```
 +PlayerScore[“Level”+ToString(Variable(CurrentLevel))]["enemies"]["killbonus"]
 ``` ```