system
May 27, 2019, 11:44am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
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 ?
system
May 27, 2019, 12:00pm
2
Reply From:
volzhs
use class_name
GDScript is a high-level, object-oriented, imperative, and gradually typed programming language built for Godot. It uses an indentation-based syntax similar to languages like Python. Its goal is to...
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))
system
May 27, 2019, 12:01pm
3
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)