It’s unnamed, so you don’t choose its name directly. You can access it indirectly by accessing the node which contains the script using get_node(), like this:
File-level classes in godot are unnamed by design. You can access them via preload/load, in which case the name of the class would be the name of the variable you assign it to. You can also access them via get_node, as @Calinou pointed out. After you have access to the node you can also use get_script on it, and you would again have access to that class.
Subclasses are a bit different. They do have a name, by which they are referenced in the parent class.
Here is a code sample, summarizing all I wrote above:
extends Node2D
# It doesn't actually have a name, but we give it one
const MyClass = preload("res://utils/my_class.gd")
# To other scripts, subclasses behave like static constants
const MySubClass = preload("res://utils/subclasses.gd").MySubClass
# Subclasses, on the other hand, have a name
class SubClass extends MyClass:
var i = 0
var classes = []
func _ready():
for i in range(4):
# Load when it is not a constant expression
classes.push_back(load(str("res://utils/classes/", i, ".gd")))
# Just call functions on scripts attached to other nodes
get_node("../another_node").do_stuff()
# ... or change properties
get_node("../yet_another_node").a += 1
print(SubClass.new().i) # == 0
# Get the script, and create a new instance of it
var yan_script = get_node("../yet_another_node").get_script()
print(yan_script.new().a)
I never try it, but i see some time a go, in build in keywords in gdscript package for atom editor, keyword “class” - maybe you just must do some think like this:
class class_name extends Node
Unfortunately, that would create a subclass instead.