+1 vote

I would like to loop though the values in constructed PoolVector2Array/PoolVector3Array's.
However in the docs, "Get" method is not available.
Is there anyway to do this currently?

extends Node 

var pos2d = PoolVector2Array()
var pos3d = PoolVector3Array()

func _process(delta):
    #pos2d = [(10,10),(10,40),(30,40)]  # <- Is  this possible?-- Expected ')' in expression
    #pos3d = ((10,10,10),(10,40,10),(30,40,40))   #<- Is  this possible?-- Expected ')' in expression

var p2_1 = Vector2(10,10)  
var p2_2 = Vector2(10,10)

var p3_1 = Vector3(10,10,10)
var p3_2 = Vector3(10,40,10)



# No "Get"method available

for p in pos2d:
    print("pos2d" + "-" + p + " = " + pos2d[p])

for p in pos3d:
    print("pos3d" + "-" + p + " = " + pos3d[p])
in Engine by (51 points)

1 Answer

+1 vote
Best answer

Here you go:

var pos2d = PoolVector2Array()

func _ready():
    pos2d = [Vector2(10, 10), Vector2(10, 40), Vector2(30, 40)]

    print("Array (initial):\n", pos2d, "\n")

    var p2 = Vector2(10,10)

    print("Array (after append):\n", pos2d, "\n")

    print("Array (1-by-1):")
    for entry in pos2d:

The 3D-case is analogous but uses Vector3 instead.

by (10,628 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.