Reply From:
kidscancode
I just saw that you’re using 4.0. You do realize that 4.0 is not even alpha stage yet?
You should only be using 4.0 if you are a developer who is working on it, or if you are testing and helping to find bugs/issues for those developers. Many things don’t work right now, and many others have changed from 3.x in ways that are not yet documented.
If you want to try and help with 4.0, you will need to follow the issues and discussions on Github, where you will find what has been changed. For example, GDScript has been changed a great deal, including many keywords becoming annotations, such as onready
. Some of the changes are summarized here:
godotengine:master
← vnen:gdscript-rewrite-squash
opened 04:22PM - 27 May 20 UTC
**EDIT**: The discussion here is quite lengthy now and a lot of cross-talk. I ca… n answer small questions here (about the current PR, not future plans) but if you have a proposal to change something I'd prefer that you open a new issue and link it here, so the discussion can be contained in a thread. If you have a feature request you need to follow the [GIP procedure](https://github.com/godotengine/godot-proposals/).
----
This is a basic version of what we call "GDScript 2.0" (not an official name since GDScript changes with each engine version). The point is that this breaks compatibility much more than the previous updates.
The reason is that we can take the opportunity to clean up both implementation and design, allowing for a less-confusing language in which we can simplify the more complex constructs into a cleaner appearance. Also the implementation of GDScript has been patched so much that it became super difficult to understand (I can get some blame for introducing static types, which increase the complexity much more).
Most of the things remain the same, so it's not a completely new language. But people will have to relearn some stuff. I will write a new documentation page with the new syntax and everything so the reference will be complete (**EDIT**: already done it in https://github.com/godotengine/godot-docs/pull/3623). Here I'll highlight most of what is change and what is still missing (which I'll be working on next).
This is only a partial version, mostly to show users what to expect sooner rather than later, and also to show what I'm working on.
## Changes
### Annotations
Some keywords have been replaced by annotations, as outlined in the proposal: https://github.com/godotengine/godot-proposals/issues/828.
`@tool`, `@onready`, and the RPC keywords (`@remote`, `@master`, `@puppet`, `@remotesync`, `@mastersync`, `@puppetsync`) are now annotations. `@tool` must be the first thing in the file (apart from comments) otherwise it doesn't work.
Exporting now uses the annotations listed in the proposal: https://github.com/godotengine/godot-proposals/issues/828#issuecomment-629270690
Ignoring warnings will also be done with annotations. But there's no warnings yet, so it's not added for now.
### `yield` is now `await`
The `yield` keyword is removed in favor of `await`. You can use `await some_signal` which works the same as `yield` did before. You can also do `await my_func()` which is the same as `yield(my_func(), "completed")` but it also works if the function isn't a coroutine: it'll just run synchronously and get the returned value. Note that if `my_func()` returns a signal, then it will wait for that signal to be emitted.
### ~~`_init` is now `new`~~
~~The `_init` constructor was declared in object but only really called in GDScript. Since you do `MyClass.new()` to create a new instance, it makes more sense to use the same name as constructor. This also simplifies type checking as it doesn't need to rename the method name in some peculiar cases.~~
I reverted this change for the reason outlined here: https://github.com/godotengine/godot/pull/39093#issuecomment-635965013
### `super` keyword for super calls
The previous syntax for super calls was to use `.func_name()` which can be confused as a continuation of the previous line. Now you to to explicitly use `super.func_name()`. If you want to call the same function you are in, then `super()` is enough. This is also valid for constructors, so the old `_init().()` syntax isn't valid anymore. There's no validation yet, but when type-checks are added back it will enforce a `super()` call in the constructor if the super class also have a custom constructor.
### First-class functions and signals
Now that we have `Signal` and `Callable` as Variant types, they are used to represent first-class object. So instead of calling `$Button.connect("button_up", self, "on_button_up")` you can get the signal and connect to the function name: `$Button.button_up.connect(on_button_up)`. This avoids the use of strings.
Note that Callable has a `call()` function. So if you want to pass functions around you need to call them like this: `var x = my_func; x.call()`. Using `x()` won't work.
### String types
Now we have `StringName` in Variant so a notation for it was added: `&"This is StringName"`. Those are interned strings which are better to use when equality tests are frequent. Since `@` is now used for annotations, writing NodePaths need the `^` prefix instead: `^"This/Is/NodePath"`.
## Broken things
Since this is an initial pull request (as I wanted to have it partially working and possible to test ASAP), a bunch of things are still not working at all, as they need to be re-implemented with the new parser code.
### Type checks
This will require quite some more time to add back. But in the bright side it should work much better than before. Including a fix to the dreaded issues with cycles.
You can use types in your code, but they won't do anything. This includes casting.
### Code completion
Since this relies partially on type checks, it will also be done later.
### Warnings
Similarly to the previous point, this also heavily relies on type-checking.
### Language server
This relied on the parser code. It will be updated to use the new parser.
### `setget`
My intention is to replace this with properties (see https://github.com/godotengine/godot-proposals/issues/844). I haven't implemented yet to wait the discussion to show possible things that I could be missing. Still, `setget` as it was will be replaced, so I didn't implement the old way.
### Some optimizations
The old code already had some optimizations in place like reducing constant expression on compilation, and replacing `range` in `for` loop to not allocate an array. This is undone for now but will be added back soon. Main reason is that the new code will be able to do a better job reducing those expressions by waiting until more information is available.
### Probably something else
I tried my best to test the code with some weird scenarios, but users never fail to surprise me. Eventually I'll go back to my project to automate GDScript testing which will avoid regressions from being introduced.
If something is broken, you can open an issue. However, unless it's something really bad I'll refrain doing anything before the next phase is completed.
I also haven't tested in release yet, so no guarantee it's fully working (note that nobody should be using the master branch in production, so this shouldn't be a big deal).
## What about traits, lambdas, etc.?
My plan is to first make GDScript work back in the way it was, apart from the actual syntax changes. Then I'll work on new features. Even though there's quite some time before Godot 4.0 enters feature freeze, I prefer to delay working on new features. If we need to release 4.0 without those, it's not the end of the world.
Again, I can’t recommend this more strongly: If you’re a beginner, you should not be using 4.0.
Hi! I’m bumping this because Godot 4.0 just entered alpha and I’m bumping into the same issue
Tadaboody | 2022-01-26 00:12
Again, because we’re only in alpha stage a lot of the documentation is not yet complete (most of us won’t really start writing docs until there’s a feature freeze).
That said, the issue here is that “onready” is now an annotation and the line above would be written
@onready var muzzle = $Muzzle
While the docs are not yet complete, there have been some updates to the GDScript doc that cover many of these new features:
GDScript reference — Godot Engine (latest) documentation in English
kidscancode | 2022-01-26 00:26
Over a year later with godot 4’s actual release and this is still the recommended answer…
Honestly, not actually answering the question and instead just telling them not to use the software is bad form, especially when your forum post is going to exist long into the future and be indexed on google for all the people looking for help down the line.
tiggerbiggo | 2023-03-05 14:45