Newbie - How to reference one script from another?

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

Hi, newbie here crossing over from Unity, I often like to refer to other c# classes I might have declared in my project e,g:

public class Foo
  private Bar bar;

  public void init()
     bar = new Bar();

In GDScript I am trying to declare bar like so:

extends Spatial

class_name Foo

var bar: Bar

extends Node

class_name Bar

But I get the following error:
‘The identifier “Bar” isn’t a valid type’

:bust_in_silhouette: Reply From: Andrea

dont know if i understood the question correctly, but if you want the Bar to have all the properties and methods of Foo plus whatever you add to the Bar script, you can extend it from the Foo script

extend "res://"
:bust_in_silhouette: Reply From: AlexTheRegent

In case of external text editor (such as Visual Studio Code) you might have to restart Godot Editor to update classnames and methods (I use Godot 3.2.3 and I have to restart Godot to refresh methods and classnames, or VSCode highlights lines as warnings/errors).