47. Your own classes and helper objects
class RewardData:
var item_id: String
var points: int func _init(new_item: String, new_points: int) -> void:
item_id = new_item
points = new_pointsfunc run() -> Array:
var reward := RewardData.new("key", 5)
return [reward.item_id, reward.points]An inner class is useful when a small helper belongs with one script record. A separate .gd file can extend RefCounted for a data/service helper, Node for a scene component, or Resource for serialized editor data.
class_name registers a file-backed Godot class in the Godot project. PCA compiles authored records dynamically; do not depend on a record’s class_name turning it into a universally registered file-backed class. Use CallScript/IncludeScript for record-to-record libraries.
In a Godot source project you can create a file such as res://custom/reward_data.gd and preload it. That file must actually be present in the project/export. Writing its path in a string does not create or package it.
