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

Add typed variables to GDScript #2200

Closed
Ace-Dragon opened this issue Jun 27, 2015 · 11 comments
Closed

Add typed variables to GDScript #2200

Ace-Dragon opened this issue Jun 27, 2015 · 11 comments

Comments

@Ace-Dragon
Copy link

So right now, every variable can be one of three types...

  • Constant - it has one value and one value only
  • Dynamic - it can have its value changed to one of any type from a string to a vector3
  • Exported - this allows you to have an adjustable value for each instance of an object

However, the downside with having to use dynamic types with all possible values that are changeable is that they are not the fastest solution around. Now I propose that GDscript gets a third main variable type, static.

The main benefit I can see is that it can potentially make scripts a bit faster, this will not replace the general dynamic type, but merely give the developer another way to optimize logic and make code more readable (because the interpreter would not have to check what type the value is and will throw an error if the wrong type of value is assigned).


The syntax would work similar to how the export system works, so you could have like...

static var health = int(5)
static var percent = float(12.5)
static var message = "hello"
static var rotation = Vector3(0,1,0)
static var list = [0,1,2,3,4]
static var blue = Color(0,0.5,1)

Would this be worth adding to Godot (which would depend on how much speed gain scripts can get in practice)?

@reduz
Copy link
Member

reduz commented Jun 27, 2015

This is something i really, really want to do (typed variables), as it
would allow more ability to optimize code and improve code completion..
still, would rather wait a bit for this as it's quite a big an
unstabilizing change

On Sat, Jun 27, 2015 at 5:39 PM, Ace-Dragon notifications@github.com
wrote:

So right now, every variable can be one of three types...

  • Constant - it has one value and one value only
  • Dynamic - it can have its value changed to one of any type from a
    string to a vector3
  • Exported - this allows you to have an adjustable value for each
    instance of an object

However, the downside with having to use dynamic types with all possible
values that are changeable is that they are not the fastest solution
around. Now I propose that GDscript gets a third main variable type,
static.

The main benefit I can see is that it can potentially make scripts a bit
faster, this will not replace the general dynamic type, but merely give the
developer another way to optimize logic and make code more readable
(because the interpreter would not have to check what type the value is and

will throw an error if the wrong type of value is assigned).

The syntax would work similar to how the export system works, so you could
have like...

static var health = int(5)
static var percent = float(12.5)
static var message = "hello"
static var rotation = Vector3(0,1,0)
static var list = [0,1,2,3,4]
static var blue = Color(0,0.5,1)

Would this be worth adding to Godot (which would depend on how much speed
gain scripts can get in practice)?


Reply to this email directly or view it on GitHub
#2200.

@Ace-Dragon
Copy link
Author

I see, I didn't know that adding this would entail a very involved process.

I don't need it today (my game works very smooth right now), but hopefully it can be done within the next several version releases.

@leonkrause leonkrause changed the title REQUEST: New variable flag type, "static" Add typed variables to GDScript Nov 11, 2015
@reduz
Copy link
Member

reduz commented Jan 2, 2016

after a long discussion, GDScript will be left untyped. We may make or bind an alternative language that is typed and leave gdscript as is.

@reduz reduz closed this as completed Jan 2, 2016
@bojidar-bg
Copy link
Contributor

@reduz Recently we discussed that this is probably no longer the case, as it would make JIT-ing much simpler... so this should be reopened, right? 😃

@reduz
Copy link
Member

reduz commented Dec 30, 2016 via email

@bojidar-bg bojidar-bg reopened this Dec 30, 2016
@neikeq
Copy link
Contributor

neikeq commented Dec 30, 2016

I prefer Dart's syntax:

var imVariant = "hi"
String imString = "ok thx"

@kefik
Copy link

kefik commented Dec 2, 2017

Not having optional static typing that is especially used for ALL engine API means the learning curve for using Godot skyrockets. The constant requirement to consult documentation is frustrating. Sorry guys ;(

@DriNeo
Copy link

DriNeo commented Dec 2, 2017

If that "var" keyword means "variant", neikeq's syntax makes sense.
But if "var" means "variable" (note that the keyword "const" is used in replacement of "var".) reduz's syntax sounds like the most consistent. Just my two cents post .

@Calinou
Copy link
Member

Calinou commented Dec 2, 2017

Not having optional static typing that is especially used for ALL engine API means the learning curve for using Godot skyrockets. The constant requirement to consult documentation is frustrating. Sorry guys ;(

Juan has some plans about implementing optional static typing in GDScript, which may be implemented in a future Godot 3.x release (it won't be done for 3.0, as it is currently in feature freeze). This could also bring performance improvements when making use of static types.

Also, note that you can access the API documentation very easily from the editor, you can even hold Ctrland click on a class name to access its built-in documentation.

@reduz
Copy link
Member

reduz commented Dec 2, 2017 via email

@akien-mga akien-mga added this to the 3.1 milestone Dec 4, 2017
@akien-mga
Copy link
Member

This is a duplicate of #10630, which is more recent but also has some more activity, so closing this one in favour of the other. If any information described here is missing from the other issue, feel free to link it/copy it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants