Attention | Topic was automatically imported from the old Question2Answer platform. | |
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 treesInAoe
using this code:
func get_trees_in_aoe() -> PackedVector2Array:
var trees = scene.trees
var treesInAoe = []
for tile in aoe_tiles:
print(trees.has(tile))
if trees.has(tile):
print("There is a tree at: " + str(tile))
treesInAoe.append(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?
EDIT:
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):
print("found")
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