How to save a subclass?

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

Say I have a class and I load it into a script as this issue here.

How do I save it from the current script? The last comment says “Well, we can have subclasses export variables as well, can’t we?” What does that comment mean?

extends Node

const Grid = preload("addons/terrain/array2d.gd")

# Error: export hint is not a type or resource
export(Grid) var save = null

func _ready():
    save = Grid.create(8,5,1)

Or perhaps I am thinking about this in the wrong way? Would the Godot way be to put the subclass script on a sub-node?

:bust_in_silhouette: Reply From: Zylann

This is currently not supported. In my terrain plugin I had to work around it by putting the raw grid array in export, and wrapping it later with C-style static functions:

var _data = []

func _get_property_list():
	return [
		# We just want to hide the following properties
		{
			"name": "_data",
			"type": TYPE_ARRAY,
			"usage": PROPERTY_USAGE_STORAGE
		}
	]

Util.grid_resize(_data, new_size)
var cp = Util.grid_clone(_data)
# Etc...

I think the last comment was a suggestion to have this feature in the future… then nobody looked into it yet. If you want to discuss this issue you can eventually do it on Github.