Why this array contains garbage ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DriNeo

I want to fill an array with SegmentShapes2D and draw them.But I discovered the array is full of vector2.
Here’s some bits of code.

var newSegmt = SegmentShape2D.new()
newSegmt.set_a(Tracer.get_position())
newSegmt.set_b(Tracer.get_position())  
Wall.shape_owner_add_shape(WallOwnerID, newSegmt)
WallSegment.push_back(newSegmt)

Then

func _draw():
	print(WallSegment)
	for i in WallSegment:
	draw_line(i.a, i.b, LineColor, 5.0)

The error is "invalid get index a on base Vector2.
The print show that…

[(0, 0), [SegmentShape2D:1324]]

I just pushed back a shape why there is a Vector 2 please ?

Maybe you started with one. Where’s the code where you initialize the array?

kidscancode | 2019-04-05 05:31

The array was declared with a type hint as below

var myArray:Array

The problem was gone when I declare the array in a more usual way.

var myArray = []

DriNeo | 2019-04-05 21:21