浏览代码

Document constants being flat in GDScript

See https://github.com/godotengine/godot/issues/30212.
Hugo Locurcio 5 年之前
父节点
当前提交
bb143bc497
共有 1 个文件被更改,包括 7 次插入1 次删除
  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
 ^^^^^
 ^^^^^