You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am developing a game using Godot 4, where data structures such as dictionaries are extensively used to manage information about characters, items, and various in-game elements.
Describe the problem or limitation you are having in your project
Currently, when creating dictionaries in GDScript, I must explicitly write each key-value pair, even if the keys match the variable names. This results in verbose and repetitive code, especially when dealing with objects that have multiple properties. For example:
varname="Mario"varage=30varcharacter= { "name": name, "age": age }
This verbosity makes the code less readable and harder to maintain, especially when there are many properties involved.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose adding a Property Shorthand Syntax to GDScript, similar to what exists in JavaScript (ES6). This syntax would allow developers to create dictionaries or objects more concisely when the keys are identical to the variable names.
For example, the code above could be simplified as follows:
varname="Mario"varage=30varcharacter= { name, age }
This enhancement would:
Improve code readability and reduce verbosity.
Speed up development by removing redundant code.
Align GDScript with modern scripting language conventions, making it more intuitive for developers familiar with other languages like JavaScript or Python.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The implementation would involve extending the parser for dictionary creation in GDScript to recognize when a variable name is used without explicitly defining a key.
Current Syntax:
varname="Mario"varage=30varcharacter= { "name": name, "age": age }
Proposed Syntax:
varname="Mario"varage=30varcharacter= { name, age }
Pseudo-Code for Parser Adjustment:
When parsing dictionary entries:
If the entry is written as { variable_name }, automatically expand it to { "variable_name": variable_name }.
Ensure compatibility with existing dictionary syntax and avoid conflicts with other GDScript features.
If this enhancement will not be used often, can it be worked around with a few lines of script?
While the current syntax is functional, it is verbose and requires repetitive code. There is no simple workaround to achieve the same level of readability and conciseness.
Is there a reason why this should be core and not an add-on in the asset library?
This feature is a language-level enhancement, not something that can be implemented as an add-on. It requires modifications to the GDScript parser and is fundamental to how dictionaries are written in the language. Adding it to the core will benefit all GDScript users by improving the overall developer experience.
The text was updated successfully, but these errors were encountered:
I like the underlying idea, but I'd personally be nervous about the specific syntax
{ item1, item2, item3 }
as that looks like it would be denoting an unordered set. It's the same syntax that Python uses for sets, and also how sets are often depicted in mathematics in general:
Describe the project you are working on
I am developing a game using Godot 4, where data structures such as dictionaries are extensively used to manage information about characters, items, and various in-game elements.
Describe the problem or limitation you are having in your project
Currently, when creating dictionaries in GDScript, I must explicitly write each key-value pair, even if the keys match the variable names. This results in verbose and repetitive code, especially when dealing with objects that have multiple properties. For example:
This verbosity makes the code less readable and harder to maintain, especially when there are many properties involved.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose adding a Property Shorthand Syntax to GDScript, similar to what exists in JavaScript (ES6). This syntax would allow developers to create dictionaries or objects more concisely when the keys are identical to the variable names.
For example, the code above could be simplified as follows:
This enhancement would:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The implementation would involve extending the parser for dictionary creation in GDScript to recognize when a variable name is used without explicitly defining a key.
Current Syntax:
Proposed Syntax:
Pseudo-Code for Parser Adjustment:
When parsing dictionary entries:
{ variable_name }
, automatically expand it to{ "variable_name": variable_name }
.Examples:
Single variable shorthand:
Expands to:
Mixed shorthand and explicit keys:
If this enhancement will not be used often, can it be worked around with a few lines of script?
While the current syntax is functional, it is verbose and requires repetitive code. There is no simple workaround to achieve the same level of readability and conciseness.
Is there a reason why this should be core and not an add-on in the asset library?
This feature is a language-level enhancement, not something that can be implemented as an add-on. It requires modifications to the GDScript parser and is fundamental to how dictionaries are written in the language. Adding it to the core will benefit all GDScript users by improving the overall developer experience.
The text was updated successfully, but these errors were encountered: