Description
Bugsquad edit: This proposal is a superset of #162.
EDIT: Tried to format it according to the 'template'.
Describe the project you are working on:
I was working on a game using Godot. (Have since moved to another engine due to many issues with Godot.)
Describe the problem or limitation you are having in your project:
(Original text)
The main reason I want it is due to Array and Dictionary type not being able to receive null values and I want to be able to use null values as the "default" value for functions.
This is a very common pattern in my pre-existing code and without this ability I'm not sure what to use as "default" values. Empty arrays and dictionaries? That could cause needless memory allocations I think. Also, there could be a difference in meaning between passing an empty array and passing null to a function, for example. Also it is simpler to just use null and compare/check for null.
Dictionary is used as an 'anonymous object' very often, so it makes a lot of sense to allow null. Since the type does not allow it, union types could help.
This is the biggest issue that makes me not able to use Typed GDScript more in my code.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Union types would be written as Type1 | Type2
in place of the type.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Examples:
# heal the target (which has its data in a Dictionary) if specified, otherwise if no target specified, heal self
func heal(target: Dictionary| null = null):
# heal
...
# a function that receives a parameter that is either an int or a String
func do_something(parameter: int | String):
# do something with the parameter
...
# apply damage to a Player character or an Enemy character
func apply_damage(target: Player | Enemy):
# apply the damage
...
If this enhancement will not be used often, can it be worked around with a few lines of script?:
The workaround is to not specifiy types and thus lose type safety.
Is there a reason why this should be core and not an add-on in the asset library?:
It is part of GDScript which is core.
Metadata
Metadata
Assignees
Type
Projects
Status