Importing another a .gd script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tybobobo
:warning: Old Version Published before Godot 3 was released.

How to I make a .gd script import another .gd script? :S
I am unable to import it even when it is in the same folder using “import ”

My goal is to be able to load another script which returns the default variables depending on key :slight_smile:

:bust_in_silhouette: Reply From: Bojidar Marinov

Use preload for other scripts, it is simple.

Like so:

const DefaultManager = preload("default_manager.gd") # Relative path
onready var default_manager = DefaultManager.new()

Note that if you want to make a static class, you might want to have a look at autoloads.

onready var GF = preload("Scripts/GameFunctions.gd").new() Another sexier way too :smiley:

wombatTurkey | 2016-05-18 08:23

@wombatTurkey Yeah, but I like the two-step one more. Also, in both cases it might be way simpler to use global-exposed singleton autoloads.

Bojidar Marinov | 2016-05-18 08:36

Yeah, I was just fooling around, love how we can chain stuff tbh

wombatTurkey | 2016-05-18 08:57