Comparing 2 PackedVector2Arrays always returns "false"

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

I have two arrays made out of Vector2-values.
trees and aoeTiles.
trees outputs as [(1, 1)] and aoeTiles outputs as:

[(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), ... (22, 22)]

When I try to append all the vectors of trees that are in aoeTiles to treesInAoeusing this code:

func get_trees_in_aoe() -> PackedVector2Array:
var trees = scene.trees
var treesInAoe = []
for tile in aoe_tiles:
	if trees.has(tile):
		print("There is a tree at: " + str(tile))
return treesInAoe

it always prints false and returns an empty array.

What am I doing wrong here?
It should theoretically return true and an array of [(1, 1)] or not?

When using print(trees.find(tile)) it always returns -1.
So apparently the Vector (1, 1) is not present in aoe_tiles but still gets printed.

extends Node

func _ready():
	var trees = PackedVector2Array([Vector2(1, 1)])
	var aoe_tiles = PackedVector2Array([Vector2(1, 1), Vector2(2, 2), Vector2(3, 3)])
	for tile in aoe_tiles:
		if trees.has(tile):

This little test works so I suspect scene.trees isn’t what you think it is. Perhaps debug print the values (I realise the post stated what they were but, you know - worth revisiting those assumptions)

spaceyjase | 2023-04-13 12:29

Hey, thank you for your reply.
I was able to find out that trees was actually an array of Vector2i and the other array was just Vector2.
That way it couldn’t find it.

CasualCha0s | 2023-04-13 19:57