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/05/06 20:03]
bouh [Array]
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 91: Line 91:
 <note tip>On structures, `<child_variable>` is the name of the child variable, and on Arrays it is the index of the child variable. Note that only numbers work as indices for Arrays.</note> <note tip>On structures, `<child_variable>` is the name of the child variable, and on Arrays it is the index of the child variable. Note that only numbers work as indices for Arrays.</note>
  
-If a child variable doesn't exist, GDevelop creates it, and returns `0` by default.+If a child variable doesn't exist, GDevelop creates it.
  
 <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 103: 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"]
 ``` ```