Browse Source

Merge pull request #3742 from Calinou/gdscript-flat-constants

Document constants being flat in GDScript
Rémi Verschelde 5 years ago
parent
commit
5f88d911a9
1 changed files with 7 additions and 1 deletions
  1. 7 1
      getting_started/scripting/gdscript/gdscript_basics.rst

+ 7 - 1
getting_started/scripting/gdscript/gdscript_basics.rst

@@ -631,7 +631,7 @@ expressions and must be assigned on initialization.
     const E = [1, 2, 3, 4][0] # Constant expression: 1.
     const E = [1, 2, 3, 4][0] # Constant expression: 1.
     const F = sin(20) # 'sin()' can be used in constant expressions.
     const F = sin(20) # 'sin()' can be used in constant expressions.
     const G = x + 20 # Invalid; this is not a constant expression!
     const G = x + 20 # Invalid; this is not a constant expression!
-    const H = A + 20 # Constant expression: 25.
+    const H = A + 20 # Constant expression: 25 (`A` is a constant).
 
 
 Although the type of constants is inferred from the assigned value, it's also
 Although the type of constants is inferred from the assigned value, it's also
 possible to add explicit type specification::
 possible to add explicit type specification::
@@ -641,6 +641,12 @@ possible to add explicit type specification::
 
 
 Assigning a value of an incompatible type will raise an error.
 Assigning a value of an incompatible type will raise an error.
 
 
+.. note::
+
+    Since arrays and dictionaries are passed by reference, constants are "flat".
+    This means that if you declare a constant array or dictionary, it can still
+    be modified afterwards. They can't be reassigned with another value though.
+
 Enums
 Enums
 ^^^^^
 ^^^^^