0 votes

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] ?

in Engine by (28 points)

1 Answer

0 votes

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)]

by (28 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.