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/06 10:48]
midhil457 [Boolean]
gdevelop5:all-features:variables [2021/11/22 23:06] (current)
Line 32: Line 32:
 A variable with the *Boolean* data type contains the simplest form of information: either yes or no, 1 or 0, true or false. They are useful as they can be easily toggled. A variable with the *Boolean* data type contains the simplest form of information: either yes or no, 1 or 0, true or false. They are useful as they can be easily toggled.
  
-====== Headline ======+#### Adding a boolean 
 +A boolean can be added by clicking the wrench** icon→Primitive types→Convert to boolean**.
  
 +{{:gdevelop5:tutorials:toggles1.png|}}
 +
 +#### Changing the value of the boolean
 +
 +There are two ways you can change the state of the boolean.
 +
 +**Modify the boolean value**
 +
 +You can set the boolean value to `"true"` or `"false"`.
 +
 +**Toggle the boolean value**
 +
 +You can toggle between the two states. If the value was True, it will be changed to False and vice versa.
 +
 +#### Checking the value of the boolean
 +
 +**Compare the boolean value**
 +
 +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**.
  
 ### Structure ### Structure
Line 49: 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 56: 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 64: 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 72: 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"]
 ``` ```