Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
24. July 2018


Most scripting languages, GDScript included, are type-less.  Instead of explicitly declaring variable types in script, it is inferred by the compiler or interpreter.   This can make code easier to write but can also make it harder to maintain, especially as complexity increases.  This is why you see solutions like TypeScript for JavaScript, this adds a type layer on top of a type-less language.  If you were hoping to see type support added to GDScript, well great news, that’s exactly what just happened!

In the upcoming release of Godot 3.1, a completely optionial type system has been added to Godot 3.1.

From the Godot news page, details of how the new type system can help:

It is quite common to use a variable only with values of the same type. With the dynamic nature of GDScript, you can inadvertently overwrite a variable with a different type and break your code logic in a way that might be hard to realize.

For instance, if your function expects a number, but you missed an input validation somewhere and is passing a string to it instead, you only will see an error at runtime (and only if you reach that point). In a larger code base, it's quite easy to miss things like that.

With type hints, Godot can know beforehand that you are passing the wrong type and show an error while you are editing the related code, even if you never run it.

You can learn a great deal more about the new type system in Godot 3.1 here.  To see the syntax in action, check out the video below.

GameDev News


blog comments powered by Disqus

See More Tutorials on DevGa.me!

Month List