length(Vector2) "not declared in current class"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Squash

pretty much just the title, I’m trying to get the length of a Vector2, and it’s telling me:

The method “length” isn’t declared in the current class.

the script extends Node2D, I’ve tried restarting, and capitalizing the “L” in length to make sure. The docs say it exists as a method. I don’t know what else to try. I’m probably missing something obvious, help?

:bust_in_silhouette: Reply From: Lopy

For a var v2 := Vector2(1, 1), You use v2.length(), because length() is a function of Vector2.
You only write f() directly if “f” is a function of the class you are defining (the “func f” is in this file or one you extend), or if it is “static”. There are many static functions, like cos(), print(), etc.
To make your own static function, just add a “static” on the left of your func. However, they are then called by using MyClass.f().

Thank you that was a good explanation, but now I’m getting another error, forgive my incompetence :confused:

Imgur: The magic of the Internet

edit: It’s working now, thank you.

Squash | 2020-12-27 20:54