Is there any way to "import" one gdscript to another like python?

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

I have created a simple math library for matrix calculation and I want to use it in many places in my game. is there any way to import/include the library ?

:bust_in_silhouette: Reply From: volzhs

use class_name

sample code

extends Object # my_class.gd

class_name MyClass

static func sum(a,b):
	return a+b

use it in another script

extends Node # another.gd

func _ready()
    print(MyClass.sum(1,2))
:bust_in_silhouette: Reply From: Dlean Jeans

You can add class_name MatrixMath to the script to use it anywhere in the game. Make sure all of the functions in there are static.

class_name MatrixMath

static func do_calculation(matrix):
    # math stuff
    return matrix

Somewhere in the project:

matrix = MatrixMath.do_calculation(matrix)