Skip to main content
1 of 3
Seph Reed
  • 275
  • 4
  • 10

How do I create and import a class in Godot Gscript

I would like to create and import a class in gscript. Here is some non-functional pseudo code to explain what I'm trying to do:

class_name WordPrinter var my_word: String func _init(word: String) my_word = word func print_word() print(my_word) 
const word_printer = import("./word_printer.gd").new("Hello World") word_printer.print_word() 

I've found various tutorials on classes and imports, but I have yet to find a straightforward code example that works. Here are some places I've looked:

The second link above does show working code, but the imported class does not have any type definitions, and is not very useful.

Seph Reed
  • 275
  • 4
  • 10