Open btarg opened 3 days ago
See also:
The C# way looks confusing. The gdscript way looks much cleaner.
The C# way looks confusing. The gdscript way looks much cleaner.
I'm not suggesting instanceof
be the syntax if that's what you mean. Otherwise I find it much easier and quicker to work with - especially if you have to otherwise cast multiple times! For example:
if my_variable is MyCustomType my_custom_type:
print(my_custom_type.function())
elif my_variable is AnotherCustomType another_custom_type:
# so on and so forth...
The last time we discussed this, we came to the conclusion that it would be nice to have the static analyzer take into account local control flow, including type checking. This seems more consistent with GDScript's design goals (simplicity and readability) than explicit type narrowing syntax.
Describe the project you are working on
A game making heavy use of GDScript
Describe the problem or limitation you are having in your project
Casting into a variable safely currently requires quite a bit of boilerplate.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I believe GDScript casting should be more like C#.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
In C# and Java, this can be shortened as
Here is an example of how we can adopt a similar syntax in GDScript:
If this enhancement will not be used often, can it be worked around with a few lines of script?
This is an enhancement to the current way of doing things rather than a brand new feature.
Is there a reason why this should be core and not an add-on in the asset library?
This is part of GDScript