[Programming] when IDE suggests available methods , variables?

Can someone explain me why static typing is not available for arrays ?

I’m looking in docs and seeing mentioned this https://en.wikipedia.org/wiki/Liskov_substitution_principle but be honest , to me still doesn’t explain why sometimes I get suggestion after . ( statically typed ) and sometimes is questionable how to type loops with packed array to provide suggestions of available methods .

It’s much better to paste a quote rather than post screenshots.

You can statically type arrays, just not arrays within arrays. This is hard to support and you may prefer to use a Resource at that point anyways, it’s a low priority feature.

var my_1d_array: Array[Item] = [] # Allowed
var my_2d_array: Array[Array[Item]] = [] # Not allowed
var my_2d_array: Array[Array] = [] # Is allowed, but the inner array is un-typed

Maybe another confusing point is that the Array even when typed in GDScript still stores it’s data as Variants under the hood, this affects some functions like .append which take a Variant despite typing.

Was more about those type a things , not always get suggestion what can push or append .

I’m not sure what you mean? There aren’t specific suggestions for function parameters as far I know. The quote you linked is using a PackedVector3Array which is different from any Array[Vector3] type, that kind is using Vector3s under the hood so .append/.push_back will only take Vector3s.

I’ll try make some better example as not sure how to explain it as was try type a code with

And when you typearrays[Mesh.ARRAY_VERTEX].It doesn’t suggest all available methods for PackedVector3Array() :man_shrugging:

That’s because arrays is only of type Array, it can’t be typed further because it’s an array of two different types, PackedVector3Array and PackedColorArray at indecies 0 and 1 respectively. That base Array type means there’s no way for the IDE to know what type will be at each index.

1 Like

Ok , thanks for confirming.

So best is just keep looking in docs what is available to use .

Yeah keep the docs handy, Godot has built-in documentation too, pressing F1 in-editor will open a search through the docs.

If you are sure of the type you can assign an array index to a variable, for Packed___Array types this will usually not create a duplicate, some properties will and the docs will mention this, such as a Line2D’s points.

var verts: PackedVector3Array = arrays[Mesh.ARRAY_VERTEX]
verts.push_back(...)
1 Like

Usually hover over type and CMD + left click

It’s just those PackedVector3Array(), PackedColorArray()
which had different operations available , would there be some good guide how to rewrite linear algebra into GDScript code get see how can better use them ?

https://youtu.be/k7RM-ot2NWY?si=6SlYkeSv7hI4Bp61 it mostly this span which talk about points , vector . Often referred as tail and tip for all possible vectors .