How can I check if a specific Vector3 value exists within an Vector3 array?

The only error I have is in searching if a value is found within the array vector3
I would also like to know how to initialize a vector3 array

    var Positions :[] vector3 = array{}
    Words: []string =array{"hola", "pedro"}
    var TestA: []int = array{3,4,3,3,3}
    
    Test():void=
        #string
        NewWord: string = "hola"
        if(IndexString:=Words.Find[NewWord]){}
        #int
        if(IndexInt:=TestA.Find[3]){}
        #vector3
        newVector: vector3 = vector3{X:=0.0,Y:=0.0,Z:=0.0}
        if(IndexPosition:=Positions.Find[newVector]){}

#error: This function parameter expects a value of type tuple([]comparable,tuple(),comparable), but this argument is an incompatible value of type tuple([]vector3,tuple(),vector3).

Vector3 are not comparable and you can’t implement your own comparable type, either you wrap it up inside a class (which is comparable) or you convert the vector3 to a string, you could also compare each value (X,Y,Z) with its int value.

Basically, string, class and int are comparable types so use those instead

If it’s not too much trouble, could you show me how do I wrap it up inside a class?

It’s situational, you’d need to store the wrapped vectors somewhere, but something like this works

wrapped_vector := class<unique>:
    Value: vector3

# ...

MyWrapper := wrapped_vector{Value := NewVector}
MyWrapper2 := wrapped_vector{Value := NewVector2}

if(MyWrapper = MyWrapper):
    Print("Succeeds")

if(MyWraper = MyWrapper2):
    Print("Fails")
1 Like

Last question: In your experience, which would you recommend using, Array or Map? I understand how both work, but I would like to know why you would use one over the other and in what situations it is advisable to use an Array or a Map.

Depends, I’m usually using maps if I need to use .Find[] on an array at some point, indexing makes it better. I don’t know how to explain it better though, use array and when you can’t do what you want with them, use maps