@@ -118,15 +118,8 @@ If you have previous experience with statically typed languages such as
118118C, C++, or C# but never used a dynamically typed one before, it is advised you
119119read this tutorial: :ref: `doc_gdscript_more_efficiently `.
120120
121- Language
122- --------
123-
124- In the following, an overview is given to GDScript. Details, such as which
125- methods are available to arrays or other objects, should be looked up in
126- the linked class descriptions.
127-
128121Identifiers
129- ~~~~~~~~~~~
122+ -----------
130123
131124Any string that restricts itself to alphabetic characters (``a `` to ``z `` and
132125``A `` to ``Z ``), digits (``0 `` to ``9 ``) and ``_ `` qualifies as an identifier.
@@ -140,7 +133,7 @@ that are considered "confusable" for ASCII characters and emoji are not allowed
140133in identifiers.
141134
142135Keywords
143- ~~~~~~~~
136+ --------
144137
145138The following is the list of keywords supported by the language. Since
146139keywords are reserved words (tokens), they can't be used as identifiers.
@@ -226,7 +219,7 @@ in case you want to take a look under the hood.
226219+------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
227220
228221Operators
229- ~~~~~~~~~
222+ ---------
230223
231224The following is the list of supported operators and their precedence. All binary operators are `left-associative <https://en.wikipedia.org/wiki/Operator_associativity >`_,
232225including the ``** `` operator. This means that ``2 ** 2 ** 3 `` is equal to ``(2 ** 2) ** 3 ``. Use parentheses to explicitly specify precedence you need, for
@@ -338,7 +331,7 @@ example ``2 ** (2 ** 3)``. The ternary ``if/else`` operator is right-associative
338331 and :ref: `is_zero_approx() <class_@GlobalScope_method_is_zero_approx >` functions instead.
339332
340333Literals
341- ~~~~~~~~
334+ --------
342335
343336+---------------------------------+-------------------------------------------+
344337| **Example(s) ** | **Description ** |
@@ -452,7 +445,7 @@ Thus, a string can have a quote that matches the opening one, but only if it's p
452445GDScript also supports :ref: `format strings <doc_gdscript_printf >`.
453446
454447Annotations
455- ~~~~~~~~~~~
448+ -----------
456449
457450Annotations are special tokens in GDScript that act as modifiers to a script or
458451its code and may affect how the script is treated by the Godot engine or
@@ -538,7 +531,7 @@ can replace the above code with a single line::
538531 as an error by default. We do not recommend disabling or ignoring it.
539532
540533Comments
541- ~~~~~~~~
534+ --------
542535
543536Anything from a ``# `` to the end of the line is ignored and is
544537considered a comment.
@@ -588,7 +581,7 @@ of a file. Dedicated formatting options are also available. See
588581 @export var exported_value
589582
590583Code regions
591- ~~~~~~~~~~~~
584+ ------------
592585
593586Code regions are special types of comments that the script editor understands as
594587*foldable regions *. This means that after writing code region comments, you can
@@ -656,7 +649,7 @@ folding code regions.
656649 group multiple elements together.
657650
658651Line continuation
659- ~~~~~~~~~~~~~~~~~
652+ -----------------
660653
661654A line of code in GDScript can be continued on the next line by using a backslash
662655(``\ ``). Add one at the end of a line and the code on the next line will act like
@@ -990,11 +983,8 @@ will set the value of ``x`` to a callable with ``$Sprite2D`` as the object and
990983
991984You can call it using the ``call `` method: ``x.call(PI) ``.
992985
993- Data
994- ----
995-
996986Variables
997- ~~~~~~~~~
987+ ---------
998988
999989Variables can exist as class members or local to functions. They are
1000990created with the ``var `` keyword and may, optionally, be assigned a
@@ -1048,7 +1038,7 @@ Valid types are:
10481038 the project settings. See :ref: `doc_gdscript_warning_system ` for details.
10491039
10501040Initialization order
1051- ^^^^^^^^^^^^^^^^^^^^
1041+ ~~~~~~~~~~~~~~~~~~~~
10521042
10531043Member variables are initialized in the following order:
10541044
@@ -1094,7 +1084,7 @@ Member variables are initialized in the following order:
10941084 or remove the empty dictionary assignment (``= {} ``).
10951085
10961086Static variables
1097- ^^^^^^^^^^^^^^^^
1087+ ~~~~~~~~~~~~~~~~
10981088
10991089A class member variable can be declared static::
11001090
@@ -1198,7 +1188,7 @@ and must be placed at the top of the script, before ``class_name`` and ``extends
11981188See also `Static functions `_ and `Static constructor `_.
11991189
12001190Casting
1201- ^^^^^^^
1191+ ~~~~~~~
12021192
12031193Values assigned to typed variables must have a compatible type. If it's needed to
12041194coerce a value to be of a certain type, in particular for object types, you can
@@ -1238,7 +1228,7 @@ the scene tree::
12381228 ($AnimPlayer as AnimationPlayer).play("walk")
12391229
12401230Constants
1241- ~~~~~~~~~
1231+ ---------
12421232
12431233Constants are values you cannot change when the game is running.
12441234Their value must be known at compile-time. Using the
@@ -1270,7 +1260,7 @@ You can also create constants inside a function, which is useful to name local
12701260magic values.
12711261
12721262Enums
1273- ^^^^^
1263+ ~~~~~
12741264
12751265Enums are basically a shorthand for constants, and are pretty useful if you
12761266want to assign consecutive integers to some constant.
@@ -1318,7 +1308,7 @@ or ``0`` if it is the first entry in the enum. Multiple keys with the same value
13181308
13191309
13201310Functions
1321- ~~~~~~~~~
1311+ ---------
13221312
13231313Functions always belong to a `class <Classes _>`_. The scope priority for
13241314variable look-up is: local → class member → global. The ``self `` variable is
@@ -1377,7 +1367,7 @@ return early with the ``return`` keyword, but they can't return any value.
13771367 valid value to return.
13781368
13791369Referencing functions
1380- ^^^^^^^^^^^^^^^^^^^^^
1370+ ~~~~~~~~~~~~~~~~~~~~~
13811371
13821372Functions are first-class values in terms of the :ref: `Callable <class_Callable >` object.
13831373Referencing a function by name without calling it will automatically generate the proper
@@ -1406,7 +1396,7 @@ callable. This can be used to pass functions as arguments.
14061396 performance issues on direct function calls.
14071397
14081398Lambda functions
1409- ^^^^^^^^^^^^^^^^
1399+ ~~~~~~~~~~~~~~~~
14101400
14111401Lambda functions allow you to declare functions that do not belong to a class. Instead, a
14121402:ref: `Callable <class_Callable >` object is created and assigned to a variable directly.
@@ -1479,7 +1469,7 @@ Lambda functions capture the local environment::
14791469 print(a) # Prints `[1]`.
14801470
14811471Static functions
1482- ^^^^^^^^^^^^^^^^
1472+ ~~~~~~~~~~~~~~~~
14831473
14841474A function can be declared static. When a function is static, it has no access to the instance member variables or ``self ``.
14851475A static function has access to static variables. Also static functions are useful to make libraries of helper functions::
@@ -1492,14 +1482,14 @@ Lambda functions cannot be declared static.
14921482See also `Static variables `_ and `Static constructor `_.
14931483
14941484Statements and control flow
1495- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1485+ ---------------------------
14961486
14971487Statements are standard and can be assignments, function calls, control
14981488flow structures, etc (see below). ``; `` as a statement separator is
14991489entirely optional.
15001490
15011491Expressions
1502- ^^^^^^^^^^^
1492+ ~~~~~~~~~~~
15031493
15041494Expressions are sequences of operators and their operands in orderly fashion. An expression by itself can be a
15051495statement too, though only calls are reasonable to use as statements since other expressions don't have side effects.
@@ -1527,7 +1517,7 @@ Identifiers, attributes, and subscripts are valid assignment targets. Other expr
15271517an assignment.
15281518
15291519if/else/elif
1530- ^^^^^^^^^^^^
1520+ ~~~~~~~~~~~~
15311521
15321522Simple conditions are created by using the ``if ``/``else ``/``elif `` syntax.
15331523Parenthesis around conditions are allowed, but not required. Given the
@@ -1590,7 +1580,7 @@ use an ``if`` statement combined with the ``in`` operator to accomplish this::
15901580 if "varName" in get_parent(): print("varName is defined in parent!")
15911581
15921582while
1593- ^^^^^
1583+ ~~~~~
15941584
15951585Simple loops are created by using ``while `` syntax. Loops can be broken
15961586using ``break `` or continued using ``continue `` (which skips to the next
@@ -1602,7 +1592,7 @@ iteration of the loop without executing any further code in the current iteratio
16021592 statement(s)
16031593
16041594for
1605- ^^^
1595+ ~~~
16061596
16071597To iterate through a range, such as an array or table, a *for * loop is
16081598used. When iterating over an array, the current array element is stored in
@@ -1665,7 +1655,7 @@ be manipulated by calling methods on the loop variable.
16651655 node.add_to_group("Cool_Group") # This has an effect
16661656
16671657match
1668- ^^^^^
1658+ ~~~~~
16691659
16701660A ``match `` statement is used to branch execution of a program.
16711661It's the equivalent of the ``switch `` statement found in many other languages, but offers some additional features.
@@ -1676,7 +1666,7 @@ It's the equivalent of the ``switch`` statement found in many other languages, b
16761666 for example, the String ``"hello" `` is considered equal to the StringName ``&"hello" ``.
16771667
16781668Basic syntax
1679- """"""""""""
1669+ ^^^^^^^^^^^^
16801670
16811671::
16821672
@@ -1688,15 +1678,15 @@ Basic syntax
16881678 <...>
16891679
16901680Crash-course for people who are familiar with switch statements
1691- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1681+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16921682
169316831. Replace ``switch `` with ``match ``.
169416842. Remove ``case ``.
169516853. Remove any ``break ``\ s.
169616864. Change ``default `` to a single underscore.
16971687
16981688Control flow
1699- """"""""""""
1689+ ^^^^^^^^^^^^
17001690
17011691The patterns are matched from top to bottom.
17021692If a pattern matches, the first corresponding block will be executed. After that, the execution continues below the ``match `` statement.
@@ -1814,7 +1804,7 @@ The following pattern types are available:
18141804 print("Yep, you've taken damage")
18151805
18161806Pattern guards
1817- """"""""""""""
1807+ ^^^^^^^^^^^^^^
18181808
18191809A *pattern guard * is an optional condition that follows the pattern list
18201810and allows you to make additional checks before choosing a ``match `` branch.
@@ -1846,7 +1836,7 @@ you can specify a pattern guard after the list of patterns with the ``when`` key
18461836 - If it's false, then the patterns of the next branch are checked.
18471837
18481838Classes
1849- ~~~~~~~
1839+ -------
18501840
18511841By default, all script files are unnamed classes. In this case, you can only
18521842reference them using the file's path, using either a relative or an absolute
@@ -1927,7 +1917,7 @@ If you want to use ``extends`` too, you can keep both on the same line::
19271917 by the Godot editor.
19281918
19291919Inheritance
1930- ^^^^^^^^^^^
1920+ ~~~~~~~~~~~
19311921
19321922A class (stored as a file) can inherit from:
19331923
@@ -2004,7 +1994,7 @@ the function name with the attribute operator::
20041994 Signals and notifications can also be useful for these purposes.
20051995
20061996Class constructor
2007- ^^^^^^^^^^^^^^^^^
1997+ ~~~~~~~~~~~~~~~~~
20081998
20091999The class constructor, called on class instantiation, is named ``_init ``. If you
20102000want to call the base class constructor, you can also use the ``super `` syntax.
@@ -2057,7 +2047,7 @@ There are a few things to keep in mind here:
20572047 super(5)
20582048
20592049Static constructor
2060- ^^^^^^^^^^^^^^^^^^
2050+ ~~~~~~~~~~~~~~~~~~
20612051
20622052A static constructor is a static function ``_static_init `` that is called automatically
20632053when the class is loaded, after the static variables have been initialized::
@@ -2072,7 +2062,7 @@ A static constructor cannot take arguments and must not return any value.
20722062.. _doc_gdscript_basics_inner_classes :
20732063
20742064Inner classes
2075- ^^^^^^^^^^^^^
2065+ ~~~~~~~~~~~~~
20762066
20772067A class file can contain inner classes. Inner classes are defined using the
20782068``class `` keyword. They are instanced using the ``ClassName.new() ``
@@ -2099,7 +2089,7 @@ function.
20992089.. _doc_gdscript_classes_as_resources :
21002090
21012091Classes as resources
2102- ^^^^^^^^^^^^^^^^^^^^
2092+ ~~~~~~~~~~~~~~~~~~~~
21032093
21042094Classes stored as files are treated as :ref: `GDScripts <class_GDScript >`. They
21052095must be loaded from disk to access them in other classes. This is done using
@@ -2118,7 +2108,7 @@ class resource is done by calling the ``new`` function on the class object::
21182108 a.some_function()
21192109
21202110Exports
2121- ~~~~~~~
2111+ -------
21222112
21232113.. note ::
21242114
@@ -2128,7 +2118,7 @@ Exports
21282118.. _doc_gdscript_basics_setters_getters :
21292119
21302120Properties (setters and getters)
2131- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2121+ --------------------------------
21322122
21332123Sometimes, you want a class' member variable to do more than just hold data and actually perform
21342124some validation or computation whenever its value changes. It may also be desired to
@@ -2155,7 +2145,7 @@ Example::
21552145 code use that name.
21562146
21572147Alternative syntax
2158- ^^^^^^^^^^^^^^^^^^
2148+ ~~~~~~~~~~~~~~~~~~
21592149
21602150Also there is another notation to use existing class functions if you want to split the code from the variable declaration
21612151or you need to reuse the code across multiple properties (but you can't distinguish which property the setter/getter is being called for)::
@@ -2176,7 +2166,7 @@ The setter and getter must use the same notation, mixing styles for the same var
21762166 Separated setter/getter functions can have type hints, and the type must match the variable's type or be a wider type.
21772167
21782168When setter/getter is not called
2179- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2169+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21802170
21812171When a variable is initialized, the value of the initializer will be written directly to the variable.
21822172Including if the ``@onready `` annotation is applied to the variable.
@@ -2214,7 +2204,7 @@ This also applies to the alternative syntax::
22142204.. _doc_gdscript_tool_mode :
22152205
22162206Tool mode
2217- ~~~~~~~~~
2207+ ---------
22182208
22192209By default, scripts don't run inside the editor and only the exported
22202210properties can be changed. In some cases, it is desired that they do run
@@ -2239,7 +2229,7 @@ See :ref:`doc_running_code_in_the_editor` for more information.
22392229.. _doc_gdscript_basics_memory_management :
22402230
22412231Memory management
2242- ~~~~~~~~~~~~~~~~~
2232+ -----------------
22432233
22442234Godot implements reference counting to free certain instances that are no longer
22452235used, instead of a garbage collector, or requiring purely manual management.
@@ -2287,7 +2277,7 @@ freed.
22872277.. _doc_gdscript_signals :
22882278
22892279Signals
2290- ~~~~~~~
2280+ -------
22912281
22922282Signals are a tool to emit messages from an object that other objects can react
22932283to. To create custom signals for a class, use the ``signal `` keyword.
@@ -2498,7 +2488,7 @@ This also means that returning a signal from a function that isn't a coroutine w
24982488 during runtime.
24992489
25002490Assert keyword
2501- ~~~~~~~~~~~~~~
2491+ --------------
25022492
25032493The ``assert `` keyword can be used to check conditions in debug builds. These
25042494assertions are ignored in non-debug builds. This means that the expression
0 commit comments