Vector2 error

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

I have already initialized variable vel as vector2 but when i use vel.x = 0 it shows error in this line as unidentified token

:bust_in_silhouette: Reply From: jgodfrey

Without code, we can only guess, but I’m confident the problem is in your code…

I’d guess that maybe you defined the vel variable locally, within a function, and are now trying to use it from somewhere else (in a different function). If that’s the case, you need to defined the variable outside of any function. Then, you can reference it in any function in the script.

So, you want something like this (for example):

var vel = Vector2()

func _ready():
    vel = Vector2(10,10)

func _process(delta):
    vel.x = 0

The important part is that the variable was defined outside any function with var vel = Vector2()