Godot parser not recognising project_position

Godot Version

<extends Camera3D

Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.
var cam = get_tree().root.get_camera()

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
pass
cam.project_position(pos,cam.far)>

Question

<trying to get mouse position in 3d and project position seems like a good way, but its just giving me a parser error about it not being declared in the current scope>
apologies for any jank im first time using this forum

You’re getting this error because you’re trying to acess a variable outside of her scope, when you create cam inside _ready function you only can acess this variable inside the function you created her. You need to create this variable in the class scope

extends Camera3D

# This variable can be accessed from all your script
var cam

func _ready():
	cam = get_tree().root.get_camera()


func _process(delta):
	cam.project_position(pos, cam.far)

I recommend you learn some tutorials about that: https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-14/