Class @gdscript - RST
Class @gdscript - RST
.. _class_@GDScript:
@GDScript
=========
.. rst-class:: classref-introduction-group
Description
-----------
.. rst-class:: classref-introduction-group
Tutorials
---------
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Color<class_Color>`
| :ref:`Color8<class_@GDScript_method_Color8>`\ (\ r8\: :ref:`int<class_int>`, g8\:
:ref:`int<class_int>`, b8\: :ref:`int<class_int>`, a8\: :ref:`int<class_int>` =
255\ ) |
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| |void|
| :ref:`assert<class_@GDScript_method_assert>`\ (\
condition\: :ref:`bool<class_bool>`, message\: :ref:`String<class_String>` = ""\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`String<class_String>`
| :ref:`char<class_@GDScript_method_char>`\ (\ char\: :ref:`int<class_int>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Variant<class_Variant>`
| :ref:`convert<class_@GDScript_method_convert>`\ (\
what\: :ref:`Variant<class_Variant>`, type\: :ref:`int<class_int>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Object<class_Object>`
| :ref:`dict_to_inst<class_@GDScript_method_dict_to_inst>`\ (\
dictionary\: :ref:`Dictionary<class_Dictionary>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Array<class_Array>`
| :ref:`get_stack<class_@GDScript_method_get_stack>`\ (\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Dictionary<class_Dictionary>`
| :ref:`inst_to_dict<class_@GDScript_method_inst_to_dict>`\ (\
instance\: :ref:`Object<class_Object>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`bool<class_bool>`
| :ref:`is_instance_of<class_@GDScript_method_is_instance_of>`\ (\
value\: :ref:`Variant<class_Variant>`, type\: :ref:`Variant<class_Variant>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`int<class_int>` | :ref:`len<class_@GDScript_method_len>`\
(\ var\: :ref:`Variant<class_Variant>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Resource<class_Resource>`
| :ref:`load<class_@GDScript_method_load>`\ (\
path\: :ref:`String<class_String>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Resource<class_Resource>`
| :ref:`preload<class_@GDScript_method_preload>`\ (\
path\: :ref:`String<class_String>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| |void|
| :ref:`print_debug<class_@GDScript_method_print_debug>`\ (\ ...\ ) |vararg|
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| |void|
| :ref:`print_stack<class_@GDScript_method_print_stack>`\ (\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`Array<class_Array>`
| :ref:`range<class_@GDScript_method_range>`\ (\ ...\ ) |vararg|
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
| :ref:`bool<class_bool>`
| :ref:`type_exists<class_@GDScript_method_type_exists>`\ (\
type\: :ref:`StringName<class_StringName>`\ )
|
+-------------------------------------
+----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Constants
---------
.. _class_@GDScript_constant_PI:
.. rst-class:: classref-constant
.. _class_@GDScript_constant_TAU:
.. rst-class:: classref-constant
The circle constant, the circumference of the unit circle in radians. This is
equivalent to ``PI * 2``, or 360 degrees in rotations.
.. _class_@GDScript_constant_INF:
.. rst-class:: classref-constant
.. _class_@GDScript_constant_NAN:
.. rst-class:: classref-constant
.. rst-class:: classref-section-separator
----
Annotations
-----------
.. _class_@GDScript_annotation_@export:
.. rst-class:: classref-annotation
**@export**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export>`
Mark the following property as exported (editable in the Inspector dock and saved
to disk). To control the type of the exported property, use the type hint notation.
::
extends Node
# Built-in types.
@export var string = ""
@export var int_number = 5
@export var float_number: float = 5
# Enums.
@export var type: Variant.Type
@export var format: Image.Format
@export var direction: Direction
# Resources.
@export var image: Image
@export var custom_resource: CustomResource
# Nodes.
@export var node: Node
@export var custom_node: CustomNode
# Typed arrays.
@export var int_array: Array[int]
@export var direction_array: Array[Direction]
@export var image_array: Array[Image]
@export var node_array: Array[Node]
\ **Note:** Custom resources and nodes should be registered as global classes using
``class_name``, since the Inspector currently only supports global classes.
Otherwise, a less specific type will be exported instead.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_category:
.. rst-class:: classref-annotation
**@export_category**\ (\
name\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@export_ca
tegory>`
Define a new category for the following exported properties. This helps to organize
properties in the Inspector dock.
See
also :ref:`@GlobalScope.PROPERTY_USAGE_CATEGORY<class_@GlobalScope_constant_PROPERT
Y_USAGE_CATEGORY>`.
::
@export_category("Statistics")
@export var hp = 30
@export var speed = 1.25
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_color_no_alpha:
.. rst-class:: classref-annotation
**@export_color_no_alpha**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_color_no_alpha>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_COLOR_NO_ALPHA<class_@GlobalScope_constant_PR
OPERTY_HINT_COLOR_NO_ALPHA>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_custom:
.. rst-class:: classref-annotation
Allows you to set a custom hint, hint string, and usage flags for the exported
property. Note that there's no validation done in GDScript, it will just pass the
parameters to the editor.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_dir:
.. rst-class:: classref-annotation
**@export_dir**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_dir>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_DIR<class_@GlobalScope_constant_PROPERTY_HINT
_DIR>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_enum:
.. rst-class:: classref-annotation
Export
an :ref:`int<class_int>`, :ref:`String<class_String>`, :ref:`Array<class_Array>`\ \
[:ref:`int<class_int>`\ \], :ref:`Array<class_Array>`\ \
[:ref:`String<class_String>`\ \], :ref:`PackedByteArray<class_PackedByteArray>`, :r
ef:`PackedInt32Array<class_PackedInt32Array>`, :ref:`PackedInt64Array<class_PackedI
nt64Array>`, or :ref:`PackedStringArray<class_PackedStringArray>` property as an
enumerated list of options (or an array of options). If the property is
an :ref:`int<class_int>`, then the index of the value is stored, in the same order
the values are provided. You can add explicit values using a colon. If the property
is a :ref:`String<class_String>`, then the value is stored.
See
also :ref:`@GlobalScope.PROPERTY_HINT_ENUM<class_@GlobalScope_constant_PROPERTY_HIN
T_ENUM>`.
::
@export_enum("Warrior", "Magician", "Thief") var character_class: int
@export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int
@export_enum("Rebecca", "Mary", "Leah") var character_name: String
::
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_exp_easing:
.. rst-class:: classref-annotation
Export a floating-point property with an easing editor widget. Additional hints can
be provided to adjust the behavior of the widget. ``"attenuation"`` flips the
curve, which makes it more intuitive for editing attenuation properties.
``"positive_only"`` limits values to only be greater than or equal to zero.
See
also :ref:`@GlobalScope.PROPERTY_HINT_EXP_EASING<class_@GlobalScope_constant_PROPER
TY_HINT_EXP_EASING>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_file:
.. rst-class:: classref-annotation
**@export_file**\ (\ filter\: :ref:`String<class_String>` = "", ...\ ) |
vararg| :ref:`🔗<class_@GDScript_annotation_@export_file>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_FILE<class_@GlobalScope_constant_PROPERTY_HIN
T_FILE>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags:
.. rst-class:: classref-annotation
Export an integer property as a bit flag field. This allows to store several
"checked" or ``true`` values with one property, and comfortably select them from
the Inspector dock.
See
also :ref:`@GlobalScope.PROPERTY_HINT_FLAGS<class_@GlobalScope_constant_PROPERTY_HI
NT_FLAGS>`.
::
::
::
::
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_2d_navigation:
.. rst-class:: classref-annotation
**@export_flags_2d_navigation**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_navigation>`
Export an integer property as a bit flag field for 2D navigation layers. The widget
in the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/2d_navigation/layer_1<class_ProjectSettings_prope
rty_layer_names/2d_navigation/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_NAVIGATION<class_@GlobalScope_const
ant_PROPERTY_HINT_LAYERS_2D_NAVIGATION>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_2d_physics:
.. rst-class:: classref-annotation
**@export_flags_2d_physics**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_physics>`
Export an integer property as a bit flag field for 2D physics layers. The widget in
the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/2d_physics/layer_1<class_ProjectSettings_property
_layer_names/2d_physics/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_PHYSICS<class_@GlobalScope_constant
_PROPERTY_HINT_LAYERS_2D_PHYSICS>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_2d_render:
.. rst-class:: classref-annotation
**@export_flags_2d_render**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_2d_render>`
Export an integer property as a bit flag field for 2D render layers. The widget in
the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/2d_render/layer_1<class_ProjectSettings_property_
layer_names/2d_render/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_2D_RENDER<class_@GlobalScope_constant_
PROPERTY_HINT_LAYERS_2D_RENDER>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_3d_navigation:
.. rst-class:: classref-annotation
**@export_flags_3d_navigation**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_navigation>`
Export an integer property as a bit flag field for 3D navigation layers. The widget
in the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/3d_navigation/layer_1<class_ProjectSettings_prope
rty_layer_names/3d_navigation/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_NAVIGATION<class_@GlobalScope_const
ant_PROPERTY_HINT_LAYERS_3D_NAVIGATION>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_3d_physics:
.. rst-class:: classref-annotation
**@export_flags_3d_physics**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_physics>`
Export an integer property as a bit flag field for 3D physics layers. The widget in
the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/3d_physics/layer_1<class_ProjectSettings_property
_layer_names/3d_physics/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_PHYSICS<class_@GlobalScope_constant
_PROPERTY_HINT_LAYERS_3D_PHYSICS>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_3d_render:
.. rst-class:: classref-annotation
**@export_flags_3d_render**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_3d_render>`
Export an integer property as a bit flag field for 3D render layers. The widget in
the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/3d_render/layer_1<class_ProjectSettings_property_
layer_names/3d_render/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_3D_RENDER<class_@GlobalScope_constant_
PROPERTY_HINT_LAYERS_3D_RENDER>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_flags_avoidance:
.. rst-class:: classref-annotation
**@export_flags_avoidance**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_flags_avoidance>`
Export an integer property as a bit flag field for navigation avoidance layers. The
widget in the Inspector dock will use the layer names defined
in
:ref:`ProjectSettings.layer_names/avoidance/layer_1<class_ProjectSettings_property_
layer_names/avoidance/layer_1>`.
See
also :ref:`@GlobalScope.PROPERTY_HINT_LAYERS_AVOIDANCE<class_@GlobalScope_constant_
PROPERTY_HINT_LAYERS_AVOIDANCE>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_global_dir:
.. rst-class:: classref-annotation
**@export_global_dir**\
(\ ) :ref:`🔗<class_@GDScript_annotation_@export_global_dir>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_DIR<class_@GlobalScope_constant_PROPER
TY_HINT_GLOBAL_DIR>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_global_file:
.. rst-class:: classref-annotation
**@export_global_file**\ (\ filter\: :ref:`String<class_String>` = "", ...\ ) |
vararg| :ref:`🔗<class_@GDScript_annotation_@export_global_file>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_GLOBAL_FILE<class_@GlobalScope_constant_PROPE
RTY_HINT_GLOBAL_FILE>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_group:
.. rst-class:: classref-annotation
Define a new group for the following exported properties. This helps to organize
properties in the Inspector dock. Groups can be added with an optional ``prefix``,
which would make group to only consider properties that have this prefix. The
grouping will break on the first property that doesn't have a prefix. The prefix is
also removed from the property's name in the Inspector dock.
See
also :ref:`@GlobalScope.PROPERTY_USAGE_GROUP<class_@GlobalScope_constant_PROPERTY_U
SAGE_GROUP>`.
::
@export_group("Racer Properties")
@export var nickname = "Nick"
@export var age = 26
@export_group("Car Properties", "car_")
@export var car_label = "Speedy"
@export var car_number = 3
@export_group("", "")
@export var ungrouped_number = 3
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_multiline:
.. rst-class:: classref-annotation
**@export_multiline**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_multiline>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_MULTILINE_TEXT<class_@GlobalScope_constant_PR
OPERTY_HINT_MULTILINE_TEXT>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_node_path:
.. rst-class:: classref-annotation
See
also :ref:`@GlobalScope.PROPERTY_HINT_NODE_PATH_VALID_TYPES<class_@GlobalScope_cons
tant_PROPERTY_HINT_NODE_PATH_VALID_TYPES>`.
::
\ **Note:** The type must be a native class or a globally registered script (using
the ``class_name`` keyword) that inherits :ref:`Node<class_Node>`.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_placeholder:
.. rst-class:: classref-annotation
**@export_placeholder**\ (\
placeholder\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@ex
port_placeholder>`
See
also :ref:`@GlobalScope.PROPERTY_HINT_PLACEHOLDER_TEXT<class_@GlobalScope_constant_
PROPERTY_HINT_PLACEHOLDER_TEXT>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_range:
.. rst-class:: classref-annotation
Export
an :ref:`int<class_int>`, :ref:`float<class_float>`, :ref:`Array<class_Array>`\ \
[:ref:`int<class_int>`\ \], :ref:`Array<class_Array>`\ \[:ref:`float<class_float>`\
\], :ref:`PackedByteArray<class_PackedByteArray>`, :ref:`PackedInt32Array<class_Pac
kedInt32Array>`, :ref:`PackedInt64Array<class_PackedInt64Array>`, :ref:`PackedFloat
32Array<class_PackedFloat32Array>`,
or :ref:`PackedFloat64Array<class_PackedFloat64Array>` property as a range value.
The range must be defined by ``min`` and ``max``, as well as an optional ``step``
and a variety of extra hints. The ``step`` defaults to ``1`` for integer
properties. For floating-point numbers this value depends on
your
:ref:`EditorSettings.interface/inspector/default_float_step<class_EditorSettings_pr
operty_interface/inspector/default_float_step>` setting.
If hints ``"or_greater"`` and ``"or_less"`` are provided, the editor widget will
not cap the value at range boundaries. The ``"exp"`` hint will make the edited
values on range to change exponentially. The ``"hide_slider"`` hint will hide the
slider element of the editor widget.
Hints also allow to indicate the units for the edited value. Using
``"radians_as_degrees"`` you can specify that the actual value is in radians, but
should be displayed in degrees in the Inspector dock (the range values are also in
degrees). ``"degrees"`` allows to add a degree sign as a unit suffix (the value is
unchanged). Finally, a custom suffix can be provided using ``"suffix:unit"``, where
"unit" can be any string.
See
also :ref:`@GlobalScope.PROPERTY_HINT_RANGE<class_@GlobalScope_constant_PROPERTY_HI
NT_RANGE>`.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_storage:
.. rst-class:: classref-annotation
**@export_storage**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@export_storage>`
Export a property
with :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY
_USAGE_STORAGE>` flag. The property is not displayed in the editor, but it is
serialized and stored in the scene or resource file. This can be useful
for :ref:`@tool<class_@GDScript_annotation_@tool>` scripts. Also the property value
is copied when :ref:`Resource.duplicate<class_Resource_method_duplicate>`
or :ref:`Node.duplicate<class_Node_method_duplicate>` is called, unlike non-
exported variables.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@export_subgroup:
.. rst-class:: classref-annotation
**@export_subgroup**\ (\ name\: :ref:`String<class_String>`,
prefix\: :ref:`String<class_String>` =
""\ ) :ref:`🔗<class_@GDScript_annotation_@export_subgroup>`
Define a new subgroup for the following exported properties. This helps to organize
properties in the Inspector dock. Subgroups work exactly like groups, except they
need a parent group to exist.
See :ref:`@export_group<class_@GDScript_annotation_@export_group>`.
See
also :ref:`@GlobalScope.PROPERTY_USAGE_SUBGROUP<class_@GlobalScope_constant_PROPERT
Y_USAGE_SUBGROUP>`.
::
@export_group("Racer Properties")
@export var nickname = "Nick"
@export var age = 26
\ **Note:** Subgroups cannot be nested, they only provide one extra level of depth.
Just like the next group ends the previous group, so do the subsequent subgroups.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@icon:
.. rst-class:: classref-annotation
**@icon**\ (\
icon_path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_annotation_@icon
>`
Add a custom icon to the current script. The icon specified at ``icon_path`` is
displayed in the Scene dock for every node of that class, as well as in various
editor dialogs.
::
@icon("res://path/to/class/icon.svg")
\ **Note:** Only the script can have a custom icon. Inner classes are not
supported.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@onready:
.. rst-class:: classref-annotation
**@onready**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@onready>`
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@rpc:
.. rst-class:: classref-annotation
Mark the following method for remote procedure calls. See :doc:`High-level
multiplayer <../tutorials/networking/high_level_multiplayer>`.
If ``mode`` is set as ``"any_peer"``, allows any peer to call this RPC function.
Otherwise, only the authority peer is allowed to call it and ``mode`` should be
kept as ``"authority"``. When configuring functions as RPCs
with :ref:`Node.rpc_config<class_Node_method_rpc_config>`, each of these modes
respectively corresponds to
the :ref:`MultiplayerAPI.RPC_MODE_AUTHORITY<class_MultiplayerAPI_constant_RPC_MODE_
AUTHORITY>`
and :ref:`MultiplayerAPI.RPC_MODE_ANY_PEER<class_MultiplayerAPI_constant_RPC_MODE_A
NY_PEER>` RPC modes. See :ref:`RPCMode<enum_MultiplayerAPI_RPCMode>`. If a peer
that is not the authority tries to call a function that is only allowed for the
authority, the function will not be executed. If the error can be detected locally
(when the RPC configuration is consistent between the local and the remote peer),
an error message will be displayed on the sender peer. Otherwise, the remote peer
will detect the error and print an error there.
The order of ``mode``, ``sync`` and ``transfer_mode`` does not matter, but values
related to the same argument must not be used more than once. ``transfer_channel``
always has to be the 4th argument (you must specify 3 preceding arguments).
::
@rpc
func fn(): pass
@rpc("any_peer", "unreliable_ordered")
func fn_update_pos(): pass
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@static_unload:
.. rst-class:: classref-annotation
**@static_unload**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@static_unload>`
Make a script with static variables to not persist after all references are lost.
If the script is loaded again the static variables will revert to their default
values.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@tool:
.. rst-class:: classref-annotation
**@tool**\ (\ ) :ref:`🔗<class_@GDScript_annotation_@tool>`
Mark the current script as a tool script, allowing it to be loaded and executed by
the editor. See :doc:`Running code in the editor
<../tutorials/plugins/running_code_in_the_editor>`.
::
@tool
extends Node
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_annotation_@warning_ignore:
.. rst-class:: classref-annotation
::
func test():
print("hello")
return
@warning_ignore("unreachable_code")
print("unreachable")
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_@GDScript_method_Color8:
.. rst-class:: classref-method
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_assert:
.. rst-class:: classref-method
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_char:
.. rst-class:: classref-method
:ref:`String<class_String>` **char**\ (\
char\: :ref:`int<class_int>`\ ) :ref:`🔗<class_@GDScript_method_char>`
::
a = char(65) # a is "A"
a = char(65 + 32) # a is "a"
a = char(8364) # a is "€"
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_convert:
.. rst-class:: classref-method
**Deprecated:**
Use :ref:`@GlobalScope.type_convert<class_@GlobalScope_method_type_convert>`
instead.
Converts ``what`` to ``type`` in the best way possible. The ``type`` uses
the :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>` values.
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_dict_to_inst:
.. rst-class:: classref-method
:ref:`Object<class_Object>` **dict_to_inst**\ (\
dictionary\: :ref:`Dictionary<class_Dictionary>`\ ) :ref:`🔗<class_@GDScript_method_
dict_to_inst>`
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_get_stack:
.. rst-class:: classref-method
:ref:`Array<class_Array>` **get_stack**\
(\ ) :ref:`🔗<class_@GDScript_method_get_stack>`
::
func _ready():
foo()
func foo():
bar()
func bar():
print(get_stack())
.. code:: text
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_inst_to_dict:
.. rst-class:: classref-method
:ref:`Dictionary<class_Dictionary>` **inst_to_dict**\ (\
instance\: :ref:`Object<class_Object>`\ ) :ref:`🔗<class_@GDScript_method_inst_to_di
ct>`
::
Prints out:
.. code:: text
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_is_instance_of:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_instance_of**\ (\
value\: :ref:`Variant<class_Variant>`,
type\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_@GDScript_method_is_instance_
of>`
Unlike the right operand of the ``is`` operator, ``type`` can be a non-constant
value. The ``is`` operator supports more features (such as typed arrays). Use the
operator instead of this method if you do not need dynamic type checking.
Examples:
::
print(is_instance_of(a, TYPE_INT))
print(is_instance_of(a, Node))
print(is_instance_of(a, MyClass))
print(is_instance_of(a, MyClass.InnerClass))
See
also :ref:`@GlobalScope.typeof<class_@GlobalScope_method_typeof>`, :ref:`type_exist
s<class_@GDScript_method_type_exists>`, :ref:`Array.is_same_typed<class_Array_metho
d_is_same_typed>` (and other :ref:`Array<class_Array>` methods).
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_len:
.. rst-class:: classref-method
:ref:`int<class_int>` **len**\ (\
var\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_@GDScript_method_len>`
Returns the length of the given Variant ``var``. The length can be the character
count of a :ref:`String<class_String>` or :ref:`StringName<class_StringName>`, the
element count of any array type, or the size of
a :ref:`Dictionary<class_Dictionary>`. For every other Variant type, a run-time
error is generated and execution is stopped.
::
a = [1, 2, 3, 4]
len(a) # Returns 4
b = "Hello!"
len(b) # Returns 6
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_load:
.. rst-class:: classref-method
:ref:`Resource<class_Resource>` **load**\ (\
path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_@GDScript_method_load>`
::
# Load a scene called "main" located in the root of the project directory and
cache it in a variable.
var main = load("res://main.tscn") # main will contain a PackedScene resource.
\ **Important:** Relative paths are *not* relative to the script calling this
method, instead it is prefixed with ``"res://"``. Loading from relative paths might
not work as expected.
\ **Note:** Files have to be imported into the engine first to load them using this
function. If you want to load :ref:`Image<class_Image>`\ s at run-time, you may use
:ref:`Image.load<class_Image_method_load>`. If you want to import audio files, you
can use the snippet described
in :ref:`AudioStreamMP3.data<class_AudioStreamMP3_property_data>`.
\ **Note:** If
:ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectS
ettings_property_editor/export/convert_text_resources_to_binary>` is
``true``, :ref:`load<class_@GDScript_method_load>` will not be able to read
converted files in an exported project. If you rely on run-time loading of files
present within the PCK, set
:ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectS
ettings_property_editor/export/convert_text_resources_to_binary>` to ``false``.
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_preload:
.. rst-class:: classref-method
::
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_print_debug:
.. rst-class:: classref-method
|void| **print_debug**\ (\ ...\ ) |
vararg| :ref:`🔗<class_@GDScript_method_print_debug>`
.. code:: text
Test print
At: res://test.gd:15:_process()
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_print_stack:
.. rst-class:: classref-method
.. code:: text
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_range:
.. rst-class:: classref-method
\ ``range(b: int, n: int)``: Starts from ``b``, increases by steps of 1, and stops
*before* ``n``. The arguments ``b`` and ``n`` are **inclusive** and **exclusive**,
respectively.
\ **Note:** Returns an empty array if no value meets the value constraint (e.g.
``range(2, 5, -1)`` or ``range(5, 5, 1)``).
Examples:
::
::
Output:
.. code:: text
9
6
3
::
Output:
.. code:: text
0.3
0.2
0.1
.. rst-class:: classref-item-separator
----
.. _class_@GDScript_method_type_exists:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **type_exists**\ (\
type\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_@GDScript_method_type_e
xists>`
::