I wa asking myself the same question, and as it could be useful, I will answer for anyone wo need it. It's not possible to fast access keys of an object like that, not with numbers. With strings, we still get that complex virtual _get() method, but it is another area.
For purpose a basic example of an object class :
extends Object
var inventory = ["A","B","C","D"]
var i = 0
func _iter_init(arg):
i = 0
return i < inventory.size()
func _iter_next(arg):
i += 1
return i < inventory.size()
func _iter_get(arg):
return inventory[i]
func key(n:int):
return inventory[n]
And here the working code access inside a scene :
tool
extends Node
var object = preload("object.gd").new()
func _ready():
for each in object : prints(each)
A
B
C
D
An alternative, which use only the key function :
tool
extends Node
var object = preload("object.gd").new()
func _ready():
prints(object.key(0))
A