What I do not understand in particular, is: why does the constructor have both Variant.Type and class_name? And what do I do with it, if the type of data in my array is of some Variant.type? For example, Vector2. Does it only work when I have type: TYPE_OBJECT? Do I leave class_name as empty string, then? Or "Variant"? Or something else?.. I totally do not understand this.
The documentation does not elabortate too much on the matter. It says:
Array Array(base: Array, type: int, class_name: StringName, script: Variant)
Creates a typed array from the base array. A typed array can only contain elements of the given type, or that inherit from the given class, as described by this constructor's parameters:
- type is the built-in Variant type, as one the Variant.Type constants.
- class_name is the built-in class name (see Object.get_class()).
- script is the associated script. It must be a Script instance or null.
If type is not TYPE_OBJECT, class_name must be an empty StringName and script must be null.
Of course I could use static typing (I suppose):
var myArray :Array[Vector2i] = []
But in case I want this fancy constructor, I'd still like to understand how it works exactly. Could you explain me, please?