Skip to content

Commit

Permalink
Clarify @export_enum docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dalexeev committed Feb 1, 2023
1 parent 229a7c7 commit 3cce58f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions tutorials/scripting/gdscript/gdscript_exports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ annotation.
@export_category("Main Category")
@export var number = 3
@export var string = ""

@export_category("Extra Category")
@export var flag = false

Expand Down Expand Up @@ -266,6 +266,15 @@ has value 1, ``Water`` has value 2, ``Earth`` has value 4 and ``Wind``
corresponds to value 8. Usually, constants should be defined accordingly (e.g.
``const ELEMENT_WIND = 8`` and so on).

You can add specific identifiers for allowed values using a colon::

@export_flags("Self:4", "Allies:8", "Foes:16") var spell_targets = 0

You can also combine several flags::

@export_flags("Self:4", "Self and Allies:12", "Foes:16")
var spell_targets = 0

Export annotations are also provided for the physics, render, and navigation layers defined in the project settings::

@export_flags_2d_physics var layers_2d_physics
Expand All @@ -281,9 +290,9 @@ If in doubt, use boolean variables instead.
Exporting enums
---------------

Properties can be exported with a type hint referencing an enum to limit their values
to the values of the enumeration. The editor will create a widget in the Inspector, enumerating
the following as THING_1, THING_2, ANOTHER_THING. The value will be stored as an integer.
Properties can be exported with a type hint referencing an enum. The editor will
create a widget in the Inspector, enumerating the following as "Thing 1", "Thing 2",
"Another Thing". The value will be stored as an integer.

::

Expand All @@ -298,14 +307,22 @@ of the selected option (i.e. ``0``, ``1``, or ``2``).

::

@export_enum("Warrior", "Magician", "Thief") var character_class
@export_enum("Warrior", "Magician", "Thief") var character_class: int

You can add specific identifiers for allowed values using a colon::

@export_enum("Slow:30", "Average:60", "Very Fast:200") var character_speed: int

If the type is String, the value will be stored as a string.

::

@export_enum("Rebecca", "Mary", "Leah") var character_name: String

If you want to set an initial value, you must specify it explicitly::

@export_enum("Rebecca", "Mary", "Leah") var character_name: String = "Rebecca"

Exporting arrays
----------------

Expand Down

0 comments on commit 3cce58f

Please sign in to comment.