'the identifier "velocity" isn't declared in the current scope

"the identifier "velocity" isn't declared in the current scope."

godot is showing this error in my code:

extends KinematicBody2D

func _physics_process(delta):
       if Input.is_action_pressed("ui_right"):
          velocity.x += 4 
       elif Input.is_action_pressed("ui_left"):
          velocity.x += -4

for some reason, I can't find the reason why this happens pls answer

maybe the problem is with my code as I am purely a beginner and i am using godot version-3.4.2



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source