Hey, I have an Array declared with:
var liste = []
this gets filled with some RigidBodys by the _ready() function. I also have an index of type int.

Ideally I would now want to be able to say
liste[index].linear_velocity = 1

But it doesnt let me, it doesnt even show what options i have after liste[index]

Am i doing something wrong here?

  • xyz replied to this.

    lukiwas But it doesnt let me

    What do you mean by "doesn't let me"? If the array element contains a valid node reference, you should be able to access its properties.

    Editor autocomplete won't work with a regular array because interpreter cannot know the exact type of an array element prior to runtime.

    In Godot 4, you can declare it as a typed array, if the array is supposed to contain only one specific element type. In that case the autocomplete should display methods/properties for that type.

    var liste: Array[RigidBody2D] = []

    Yeah no i get that but even setting the datatype for the array is impossible for me...
    The 3.6 wiki reads that i can have a (for example) int array like this: var array: Array(int) = [1, 2, 3, 4]
    I am on version 3.6 and this exact notation copied from the wiki, results in the error "Expected end of statement ("var"), got '[' instead"
    Mind you im extending from the Spatial class and the array currently is outside any function

    • xyz replied to this.

      lukiwas Afaik you can't declare a typed a array. You can explicitly cast an element when accessing it though:

      (liste[index] as RigidBody2D).linear_velocity