How can I compare two arrays

Anybody know how i can check if a value of a first array exists in a second array? The values on the first array all exist on the second and I just need a way to get the indexes of these values from the second array

Compare macro:

Settings for macro execs and parameters

Use case

I’m actually using UEFN and we don’t use blueprints on this, only Verse

Had to quickly teach myself verse. Luckily it’s pretty close to python in syntax

output

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }


# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

# A Verse-authored creative device that can be placed in a level
CompareArrays_device := class(creative_device):



    

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=

        Array1:[]int = array{4,3,1}
        Array2:[]int = array{6,4,8,3,1}
        
        var Output : []int = array{}        
        var loopAr1 : int = 0;
        var loopAr2 : int = 0;
        for (Ar1Val : Array1):
            set loopAr2 = 0
            for (Ar2Val : Array2):                                
                if(Ar1Val = Ar2Val):
                    Print("Found {Ar1Val} at index {loopAr2}")
                    set Output += array{loopAr2}                                
                set loopAr2 += 1
            set loopAr1 += 1
        
        Print("Output")
        var outputString : string = ""
        var loopOut : int = 0
        for (O : Output):
            if(loopOut = 0):
                set outputString += "{O}"
            else:
                set outputString += ",{O}"
            set loopOut+=1
        Print(outputString)
    ```

Actually was a lot simpler because there’s a function that exists and that is Find (gets the index of a value in an array that you specified in the square brackets).

        for (IndexChosenMaps : chosenMapsArray):
            if (IndexFound := mapStrings.Find[IndexChosenMaps]):
                set indexes += array{IndexFound}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.