Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify GDScript dictionary syntax restrictions #99285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions doc/classes/Dictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</brief_description>
<description>
Dictionaries are associative containers that contain values referenced by unique keys. Dictionaries will preserve the insertion order when adding new entries. In other programming languages, this data structure is often referred to as a hash map or an associative array.
You can define a dictionary by placing a comma-separated list of [code]key: value[/code] pairs inside curly braces [code]{}[/code].
You can define a dictionary by placing a comma-separated list of [code]key: value[/code] pairs inside curly braces [code]{}[/code]. Duplicate dictionary keys are not allowed during declaration.
Creating a dictionary:
[codeblocks]
[gdscript]
Expand All @@ -21,11 +21,19 @@
var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}

# Alternative Lua-style syntax.
#
# Doesn't require quotes around keys, but only string constants can be used as key names.
# Additionally, key names must start with a letter or an underscore.
# Additionally, for key names to be usable without quotes, they must start with a letter
# or an underscore and must not be reserved identifers (such as `class` or `while`).
# Here, `some_key` is a string literal, not a variable!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be changed?

Here, some_key is a string literal

If it was true, {class = "xyz"}, class would be a string literal, but parser don't understand it.

# It is still possible to use reserved identifiers, or key names that start with a digit,
# but they must be quoted.
#
# Note that while you can mix dictionary syntaxes in a single file, you cannot use both dictionary syntaxes in a single dictionary declaration.
another_dict = {
some_key = 42,
"class" = "wizard", # The key name must be quoted here.
"2test" = 100, # The key name must be quoted here.
}
[/gdscript]
[csharp]
Expand Down
Loading