Open tdnzr opened 4 years ago
The editor highlights issues like this immediately and is very helpful in showing incorrect syntax usage. "Unexpected token" is a common error shared by at least Python and Javascript, but I agree that the message is cryptic for a beginner.
To give a clearer message the parser would need to understand the context here and I'm not sure how easy that is to achieve.
@vnen Do you know how difficult would it be to detect method calls outside of functions and print a more helpful error message accordingly?
@Calinou should be simple to add this. The Unexpected token
error is the catch-all but we can add clearer errors when the context can be inferred.
Godot version: v3.2.2 stable OS/device including version: Windows 7
Issue description:
This 1-line beginner program throws a cryptic error message:
Corresponding error message:
And it's elaborated on in the Errors tab as:
Expected Behavior: GDScript is advertised to new users for its similarity to Python. So it's bad when trivial code doesn't work for incomprehensible reasons - nobody should have to check documentation or have to google to debug a "Hello World" program.
How to Fix it: GDScript doesn't like the code above because you aren't allowed to do much of anything but define variables or functions at the base level of a script. So either make the reason for this specific error message crystal clear, or make the "Unexpected token" error message in general more clear.
Elaboration: Comprehensible error messages are very important for programming. Personally, I tried Godot Engine and GDScript for the reasons mentioned above, then got this bizarre error even when following basic, community-approved programming tutorials. For instance, I followed this tutorial by GDQuest (https://www.youtube.com/watch?v=UcdwP1Q2UlU ), and copying the code on most of the slides in that video causes the error mentioned in this issue, unless you code inside a function like _ready. Naturally, an incomprehensible error message in that situation is really bad.