Can I add index for custom class FSDirectory? (like custom iterators works)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By q4a

I have custom class FSDirectory with custom iterators and this code works fine:
var my_dir = FSDirectory.new(sub_dir1, sub_dir2) for i in my_dir: print("sub_FullName=" + i.FullName())

But I get error, if I call this:
var my_dir = FSDirectory.new(sub_dir1, sub_dir2) print("sub2_FullName=" + my_dir[1].FullName())
FileBrowser.gd:48 - Invalid get index ‘1’ (on base: ‘Object (FSDirectory.gd)’)

So, is it possible to access items of custom class via [id] ?

:bust_in_silhouette: Reply From: q4a

There is workaround. Every time you run my_dir["any_string"] - you call func _get(property): in your class, even if there is no such func. But property sould be string, or you will get error.
So you can call my_dir["0"] or my_dir["1"] ... and get what you need if you add this:

class_name FSDirectory

# your code here

func _get(property):
#add check is property in get_property_list and/or is property - really integer
return _fsObjects[int(property)]