IssueRaiser

Add generic parameters to allow strongly typing for collections

**Describe the project you are working on:** A space ship battle game **Describe the problem or limitation you are having in your project:** Just the general lack of static typing features in the gdscript language for some things **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** I was wondering if gdscript could get generics simular to C#.. it would allow us to make classes the require a type to be passed like so.. `func foo<T>(t:T)` they could also get constraints to allow static typing `func foo<T>(t:T) T : int, CustomClass` this could be used to do things like so.. ``` #only accepts numbers var veci := Vector2<int>() var veci : Vector2<int> var arr := Array<MyObject>() var arr : Array<MyObject> ``` things like so wouldn't be allowed.. ``` var veci = Vector2<int>() var arr = Array<MyObject>() ``` but things like so would.. ``` var veci = Vector2() var arr = Array() ``` **Things to note**.. - generic functions use `<>` to remove confusion between `()` which is used for calling a function - constraints can be classes, any godot object, or any hint **Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:** _see above_ **If this enhancement will not be used often, can it be worked around with a few lines of script?:** this would be used whenever someone wants static typing for a collection like a array or dictionary or numeric struct like a vector it can be worked around but it takes

Posted by Shadowblitz16 on Jul 16, 2020, 8:15 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Other)

Add generic parameters to allow strongly typing for collections

Shadowblitz16Jul 16, 2020, 8:15 PM

**Describe the project you are working on:** A space ship battle game **Describe the problem or limitation you are having in your project:** Just the general lack of static typing features in the gdscript language for some things **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** I was wondering if gdscript could get generics simular to C#.. it would allow us to make classes the require a type to be passed like so.. `func foo<T>(t:T)` they could also get constraints to allow static typing `func foo<T>(t:T) T : int, CustomClass` this could be used to do things like so.. ``` #only accepts numbers var veci := Vector2<int>() var veci : Vector2<int> var arr := Array<MyObject>() var arr : Array<MyObject> ``` things like so wouldn't be allowed.. ``` var veci = Vector2<int>() var arr = Array<MyObject>() ``` but things like so would.. ``` var veci = Vector2() var arr = Array() ``` **Things to note**.. - generic functions use `<>` to remove confusion between `()` which is used for calling a function - constraints can be classes, any godot object, or any hint **Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:** _see above_ **If this enhancement will not be used often, can it be worked around with a few lines of script?:** this would be used whenever someone wants static typing for a collection like a array or dictionary or numeric struct like a vector it can be worked around but it takes

Comments (0)

No comments yet. Start the discussion.

Comment on this issue