+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)

pos2d.append(p2_1)
pos2d.append(p2_2)

pos3d.append(p3_1)
pos3d.append(p3_2)

# No "Get"method available

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

for p in pos3d:
print("pos3d" + "-" + p + " = " + pos3d[p])
``````
in Engine

+1 vote

Here you go:

``````var pos2d = PoolVector2Array()

pos2d = [Vector2(10, 10), Vector2(10, 40), Vector2(30, 40)]

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

var p2 = Vector2(10,10)
pos2d.append(p2)

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

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

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

by (10,628 points)
selected by