How do you call class methods from an external GDScript file?

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

Quick question from a Godot newbie. I’m having trouble calling a method from a GDscript custom class. is a simple class I made with just a few getter methods, which is loaded by

However, I’ve been trying to access any of the class properties in a new Tile object, but I keep receiving a Nonexistent function error from the debugger.

Please take a look at my script files:

const TileScene = preload("res://scenes/entities/Tile.tscn")


class Tile:
    var type
    var isWall
    var sceneInstance

    func _init(type = TYPES.NULL, isWall = false):
        self.type = type
        self.isWall = isWall
        self.sceneInstance = TileScene.instance()

    func get_type():
        return self.type

    func isWall():
        return self.isWall

    func get_scene():
        return self.sceneInstance

extends TileMap

var board = null
onready var Tile = preload("res://src/")

func _ready():
    var a =
    print(a.isWall())       # <<< "Nonexistent function" error
    print(a.get_scene())    # <<< Also a "Nonexistent function" error

After running the project, the debugger displays: Invalid call. Nonexistent function 'get_scene' in base 'Reference ('.

I’ve been scratching my head for a while trying to figure out why I’m unable to call any of the class methods.

If anyone could help guide me in the right direction, I’d really appreciate it.

:bust_in_silhouette: Reply From: mollusca

You’re creating an instance of the script, not the class Tile. Try replacing

var a =


var a =

Ah, you are absolutely correct. That was kind of a “duh” moment on my part. I didn’t realize I was creating a new script instance. That makes a lot of sense, otherwise, how else would I call my enum than “Tile.TYPES”. Thanks for the help!

Corrected code:

extends TileMap

var board = null
onready var Tile = preload("res://src/")

func _ready():
    var tile =
    print(tile.get_scene())    # Output: [Node2D:570]

t_monkeyman | 2017-07-01 14:36