- Edited
I wanted to write a function which would remove items from an array based on their class-type. The problem seems to lie mostly in the fact that custom classes are not present in ClassDB as I would expect them to. I dug a bit through Github and it seems to be quite an old issue (one of the posts is from 2018, https://github.com/godotengine/godot/issues/21789). The alternative here seems to be using the ProjectSettings.get_global_class_list(), but the problem here lies in the fact that I would have to check for multiple base scripts (Script.get_base_script()), which would quickly become unfeasable with a large number of sub-classes. Here's my (rather simplistic) code for now:
func remove_by_type(card_type : Object):
var check_type = card_type.new()
if check_type is CardDefault:
var script_type : Script = check_type.get_script()
if collection.is_empty() == false:
for i in range(collection.size()):
#if collection[i] is card_type: # Does not work, local variables cannot be used as types (and neither can global ones, it seems)
##do something
#if collection[i].get_script() == script_type.get_base_script(): # Works only for the class itself, not its sub-classes
##do something
Any ideas?