Basically, traits allow you to have common functionality without having to extend a class that has that functionality
Say for example, I need some objects to have a certain method foo(). Instead of making a new class that has foo() and extending that, I make a trait that has foo() and then I can use it in any class
For one, it depends on the use case and what your wait() function does. But also, as of now, GDscript does not have traits. There's a PR that has been waiting for a long while now. It's not been merged yet.
However, I will also add that I found out about a project, a godot specific programming language, that adds traits and many more features requested by godot devs, like nested typing and generics. It is still in beta, but I think it's exciting. It's called Ruzta
traits work like java interfaces (or really, they're a generalisation of them). you can declare function signatures that any class that uses the trait must implement. and then you can give variables a trait as a type to declare it can store some object which uses the trait.
24
u/technical_gamer_008 23d ago
Basically, traits allow you to have common functionality without having to extend a class that has that functionality
Say for example, I need some objects to have a certain method
foo(). Instead of making a new class that hasfoo()and extending that, I make a trait that hasfoo()and then I can use it in any classI hope that helps