Skip to content

Commit 4a24e75

Browse files
committed
Improve GDScript Basics sidebar navigation by changing header levels
Promotes many headers up one level, so they appear in the sidebar. Removes the redundant Language header, since the whole page is about the language.
1 parent f8796c2 commit 4a24e75

File tree

1 file changed

+42
-52
lines changed

1 file changed

+42
-52
lines changed

tutorials/scripting/gdscript/gdscript_basics.rst

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,8 @@ If you have previous experience with statically typed languages such as
118118
C, C++, or C# but never used a dynamically typed one before, it is advised you
119119
read 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-
128121
Identifiers
129-
~~~~~~~~~~~
122+
-----------
130123

131124
Any 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
140133
in identifiers.
141134

142135
Keywords
143-
~~~~~~~~
136+
--------
144137

145138
The following is the list of keywords supported by the language. Since
146139
keywords 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

228221
Operators
229-
~~~~~~~~~
222+
---------
230223

231224
The following is the list of supported operators and their precedence. All binary operators are `left-associative <https://en.wikipedia.org/wiki/Operator_associativity>`_,
232225
including 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

340333
Literals
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
452445
GDScript also supports :ref:`format strings <doc_gdscript_printf>`.
453446

454447
Annotations
455-
~~~~~~~~~~~
448+
-----------
456449

457450
Annotations are special tokens in GDScript that act as modifiers to a script or
458451
its 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

540533
Comments
541-
~~~~~~~~
534+
--------
542535

543536
Anything from a ``#`` to the end of the line is ignored and is
544537
considered a comment.
@@ -573,7 +566,7 @@ considered a comment.
573566
Editor > Theme > Comment Markers** section of the Editor Settings.
574567

575568
Code regions
576-
~~~~~~~~~~~~
569+
------------
577570

578571
Code regions are special types of comments that the script editor understands as
579572
*foldable regions*. This means that after writing code region comments, you can
@@ -641,7 +634,7 @@ folding code regions.
641634
group multiple elements together.
642635

643636
Line continuation
644-
~~~~~~~~~~~~~~~~~
637+
-----------------
645638

646639
A line of code in GDScript can be continued on the next line by using a backslash
647640
(``\``). Add one at the end of a line and the code on the next line will act like
@@ -970,11 +963,8 @@ will set the value of ``x`` to a callable with ``$Sprite2D`` as the object and
970963

971964
You can call it using the ``call`` method: ``x.call(PI)``.
972965

973-
Data
974-
----
975-
976966
Variables
977-
~~~~~~~~~
967+
---------
978968

979969
Variables can exist as class members or local to functions. They are
980970
created with the ``var`` keyword and may, optionally, be assigned a
@@ -1028,7 +1018,7 @@ Valid types are:
10281018
the project settings. See :ref:`doc_gdscript_warning_system` for details.
10291019

10301020
Initialization order
1031-
^^^^^^^^^^^^^^^^^^^^
1021+
~~~~~~~~~~~~~~~~~~~~
10321022

10331023
Member variables are initialized in the following order:
10341024

@@ -1074,7 +1064,7 @@ Member variables are initialized in the following order:
10741064
or remove the empty dictionary assignment (``= {}``).
10751065

10761066
Static variables
1077-
^^^^^^^^^^^^^^^^
1067+
~~~~~~~~~~~~~~~~
10781068

10791069
A class member variable can be declared static::
10801070

@@ -1178,7 +1168,7 @@ and must be placed at the top of the script, before ``class_name`` and ``extends
11781168
See also `Static functions`_ and `Static constructor`_.
11791169

11801170
Casting
1181-
^^^^^^^
1171+
~~~~~~~
11821172

11831173
Values assigned to typed variables must have a compatible type. If it's needed to
11841174
coerce a value to be of a certain type, in particular for object types, you can
@@ -1218,7 +1208,7 @@ the scene tree::
12181208
($AnimPlayer as AnimationPlayer).play("walk")
12191209

12201210
Constants
1221-
~~~~~~~~~
1211+
---------
12221212

12231213
Constants are values you cannot change when the game is running.
12241214
Their value must be known at compile-time. Using the
@@ -1250,7 +1240,7 @@ You can also create constants inside a function, which is useful to name local
12501240
magic values.
12511241

12521242
Enums
1253-
^^^^^
1243+
~~~~~
12541244

12551245
Enums are basically a shorthand for constants, and are pretty useful if you
12561246
want to assign consecutive integers to some constant.
@@ -1298,7 +1288,7 @@ or ``0`` if it is the first entry in the enum. Multiple keys with the same value
12981288

12991289

13001290
Functions
1301-
~~~~~~~~~
1291+
---------
13021292

13031293
Functions always belong to a `class <Classes_>`_. The scope priority for
13041294
variable look-up is: local → class member → global. The ``self`` variable is
@@ -1357,7 +1347,7 @@ return early with the ``return`` keyword, but they can't return any value.
13571347
valid value to return.
13581348

13591349
Referencing functions
1360-
^^^^^^^^^^^^^^^^^^^^^
1350+
~~~~~~~~~~~~~~~~~~~~~
13611351

13621352
Functions are first-class values in terms of the :ref:`Callable <class_Callable>` object.
13631353
Referencing a function by name without calling it will automatically generate the proper
@@ -1386,7 +1376,7 @@ callable. This can be used to pass functions as arguments.
13861376
performance issues on direct function calls.
13871377

13881378
Lambda functions
1389-
^^^^^^^^^^^^^^^^
1379+
~~~~~~~~~~~~~~~~
13901380

13911381
Lambda functions allow you to declare functions that do not belong to a class. Instead, a
13921382
:ref:`Callable <class_Callable>` object is created and assigned to a variable directly.
@@ -1459,7 +1449,7 @@ Lambda functions capture the local environment::
14591449
print(a) # Prints `[1]`.
14601450

14611451
Static functions
1462-
^^^^^^^^^^^^^^^^
1452+
~~~~~~~~~~~~~~~~
14631453

14641454
A function can be declared static. When a function is static, it has no access to the instance member variables or ``self``.
14651455
A static function has access to static variables. Also static functions are useful to make libraries of helper functions::
@@ -1472,14 +1462,14 @@ Lambda functions cannot be declared static.
14721462
See also `Static variables`_ and `Static constructor`_.
14731463

14741464
Statements and control flow
1475-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
1465+
---------------------------
14761466

14771467
Statements are standard and can be assignments, function calls, control
14781468
flow structures, etc (see below). ``;`` as a statement separator is
14791469
entirely optional.
14801470

14811471
Expressions
1482-
^^^^^^^^^^^
1472+
~~~~~~~~~~~
14831473

14841474
Expressions are sequences of operators and their operands in orderly fashion. An expression by itself can be a
14851475
statement too, though only calls are reasonable to use as statements since other expressions don't have side effects.
@@ -1507,7 +1497,7 @@ Identifiers, attributes, and subscripts are valid assignment targets. Other expr
15071497
an assignment.
15081498

15091499
if/else/elif
1510-
^^^^^^^^^^^^
1500+
~~~~~~~~~~~~
15111501

15121502
Simple conditions are created by using the ``if``/``else``/``elif`` syntax.
15131503
Parenthesis around conditions are allowed, but not required. Given the
@@ -1570,7 +1560,7 @@ use an ``if`` statement combined with the ``in`` operator to accomplish this::
15701560
if "varName" in get_parent(): print("varName is defined in parent!")
15711561

15721562
while
1573-
^^^^^
1563+
~~~~~
15741564

15751565
Simple loops are created by using ``while`` syntax. Loops can be broken
15761566
using ``break`` or continued using ``continue`` (which skips to the next
@@ -1582,7 +1572,7 @@ iteration of the loop without executing any further code in the current iteratio
15821572
statement(s)
15831573

15841574
for
1585-
^^^
1575+
~~~
15861576

15871577
To iterate through a range, such as an array or table, a *for* loop is
15881578
used. When iterating over an array, the current array element is stored in
@@ -1645,7 +1635,7 @@ be manipulated by calling methods on the loop variable.
16451635
node.add_to_group("Cool_Group") # This has an effect
16461636

16471637
match
1648-
^^^^^
1638+
~~~~~
16491639

16501640
A ``match`` statement is used to branch execution of a program.
16511641
It's the equivalent of the ``switch`` statement found in many other languages, but offers some additional features.
@@ -1656,7 +1646,7 @@ It's the equivalent of the ``switch`` statement found in many other languages, b
16561646
for example, the String ``"hello"`` is considered equal to the StringName ``&"hello"``.
16571647

16581648
Basic syntax
1659-
""""""""""""
1649+
^^^^^^^^^^^^
16601650

16611651
::
16621652

@@ -1668,15 +1658,15 @@ Basic syntax
16681658
<...>
16691659

16701660
Crash-course for people who are familiar with switch statements
1671-
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1661+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16721662

16731663
1. Replace ``switch`` with ``match``.
16741664
2. Remove ``case``.
16751665
3. Remove any ``break``\ s.
16761666
4. Change ``default`` to a single underscore.
16771667

16781668
Control flow
1679-
""""""""""""
1669+
^^^^^^^^^^^^
16801670

16811671
The patterns are matched from top to bottom.
16821672
If a pattern matches, the first corresponding block will be executed. After that, the execution continues below the ``match`` statement.
@@ -1794,7 +1784,7 @@ The following pattern types are available:
17941784
print("Yep, you've taken damage")
17951785

17961786
Pattern guards
1797-
""""""""""""""
1787+
^^^^^^^^^^^^^^
17981788

17991789
A *pattern guard* is an optional condition that follows the pattern list
18001790
and allows you to make additional checks before choosing a ``match`` branch.
@@ -1826,7 +1816,7 @@ you can specify a pattern guard after the list of patterns with the ``when`` key
18261816
- If it's false, then the patterns of the next branch are checked.
18271817

18281818
Classes
1829-
~~~~~~~
1819+
-------
18301820

18311821
By default, all script files are unnamed classes. In this case, you can only
18321822
reference them using the file's path, using either a relative or an absolute
@@ -1907,7 +1897,7 @@ If you want to use ``extends`` too, you can keep both on the same line::
19071897
by the Godot editor.
19081898

19091899
Inheritance
1910-
^^^^^^^^^^^
1900+
~~~~~~~~~~~
19111901

19121902
A class (stored as a file) can inherit from:
19131903

@@ -1984,7 +1974,7 @@ the function name with the attribute operator::
19841974
Signals and notifications can also be useful for these purposes.
19851975

19861976
Class constructor
1987-
^^^^^^^^^^^^^^^^^
1977+
~~~~~~~~~~~~~~~~~
19881978

19891979
The class constructor, called on class instantiation, is named ``_init``. If you
19901980
want to call the base class constructor, you can also use the ``super`` syntax.
@@ -2037,7 +2027,7 @@ There are a few things to keep in mind here:
20372027
super(5)
20382028

20392029
Static constructor
2040-
^^^^^^^^^^^^^^^^^^
2030+
~~~~~~~~~~~~~~~~~~
20412031

20422032
A static constructor is a static function ``_static_init`` that is called automatically
20432033
when the class is loaded, after the static variables have been initialized::
@@ -2052,7 +2042,7 @@ A static constructor cannot take arguments and must not return any value.
20522042
.. _doc_gdscript_basics_inner_classes:
20532043

20542044
Inner classes
2055-
^^^^^^^^^^^^^
2045+
~~~~~~~~~~~~~
20562046

20572047
A class file can contain inner classes. Inner classes are defined using the
20582048
``class`` keyword. They are instanced using the ``ClassName.new()``
@@ -2079,7 +2069,7 @@ function.
20792069
.. _doc_gdscript_classes_as_resources:
20802070

20812071
Classes as resources
2082-
^^^^^^^^^^^^^^^^^^^^
2072+
~~~~~~~~~~~~~~~~~~~~
20832073

20842074
Classes stored as files are treated as :ref:`GDScripts <class_GDScript>`. They
20852075
must be loaded from disk to access them in other classes. This is done using
@@ -2098,7 +2088,7 @@ class resource is done by calling the ``new`` function on the class object::
20982088
a.some_function()
20992089

21002090
Exports
2101-
~~~~~~~
2091+
-------
21022092

21032093
.. note::
21042094

@@ -2108,7 +2098,7 @@ Exports
21082098
.. _doc_gdscript_basics_setters_getters:
21092099

21102100
Properties (setters and getters)
2111-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2101+
--------------------------------
21122102

21132103
Sometimes, you want a class' member variable to do more than just hold data and actually perform
21142104
some validation or computation whenever its value changes. It may also be desired to
@@ -2135,7 +2125,7 @@ Example::
21352125
code use that name.
21362126

21372127
Alternative syntax
2138-
^^^^^^^^^^^^^^^^^^
2128+
~~~~~~~~~~~~~~~~~~
21392129

21402130
Also there is another notation to use existing class functions if you want to split the code from the variable declaration
21412131
or you need to reuse the code across multiple properties (but you can't distinguish which property the setter/getter is being called for)::
@@ -2156,7 +2146,7 @@ The setter and getter must use the same notation, mixing styles for the same var
21562146
Separated setter/getter functions can have type hints, and the type must match the variable's type or be a wider type.
21572147

21582148
When setter/getter is not called
2159-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2149+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21602150

21612151
When a variable is initialized, the value of the initializer will be written directly to the variable.
21622152
Including if the ``@onready`` annotation is applied to the variable.
@@ -2194,7 +2184,7 @@ This also applies to the alternative syntax::
21942184
.. _doc_gdscript_tool_mode:
21952185

21962186
Tool mode
2197-
~~~~~~~~~
2187+
---------
21982188

21992189
By default, scripts don't run inside the editor and only the exported
22002190
properties can be changed. In some cases, it is desired that they do run
@@ -2219,7 +2209,7 @@ See :ref:`doc_running_code_in_the_editor` for more information.
22192209
.. _doc_gdscript_basics_memory_management:
22202210

22212211
Memory management
2222-
~~~~~~~~~~~~~~~~~
2212+
-----------------
22232213

22242214
Godot implements reference counting to free certain instances that are no longer
22252215
used, instead of a garbage collector, or requiring purely manual management.
@@ -2267,7 +2257,7 @@ freed.
22672257
.. _doc_gdscript_signals:
22682258

22692259
Signals
2270-
~~~~~~~
2260+
-------
22712261

22722262
Signals are a tool to emit messages from an object that other objects can react
22732263
to. To create custom signals for a class, use the ``signal`` keyword.
@@ -2478,7 +2468,7 @@ This also means that returning a signal from a function that isn't a coroutine w
24782468
during runtime.
24792469

24802470
Assert keyword
2481-
~~~~~~~~~~~~~~
2471+
--------------
24822472

24832473
The ``assert`` keyword can be used to check conditions in debug builds. These
24842474
assertions are ignored in non-debug builds. This means that the expression

0 commit comments

Comments
 (0)