How do I find values and compare them in 2 arrays?

0 favourites
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • It will work perfectly if there are no duplicate values, for the duplicates the function logic needs tweaking a lot. I will take a look if I get some spare time or feel free to have a think about it.

    About the game design, how do you know the second L is the one missing from the second array if they're identical values, is it always checking in the order of array 1 ? Technically L does exist but you want to output 3.

  • Ok no problem. Ok, let's explain better:

    About order, always will start from 0 -> End of array

    So, as you know the values are:

    1 = same position

    2 = different positon

    3 = not exist

    Array1 = HELLO

    Array2 = HLEEO

    What means? From the result start from 0 to 4 (array width). As we already detect 1 L to array2

    when continue with the next step, the second L will not detect it in array2 because already checked before.

    Make sense?

    Another example:

    Array1 = HELLO

    Array2 = EEEEE

    This means:

    3,1,3,3,3

    As we detect same position and this we need to keep.

    I hope make sense now. Thanks again! :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok take a look at this attempt. I use a third array because of this duplicate business. dropbox.com/s/8dnnzqugt6y877d/arraychecks2.c3p

  • It's much better but still something is missing... :)

    I understand what you have done, but basically it's a bit different.

    So, from this example:

    Array1:

    H,3

    E,2

    L,1

    L,1

    O,3

    Array2:

    E

    L

    L

    L

    L

    It's ok as you detect the duplicates but the correct result need to be:

    Array1:

    H,2

    E,3

    L,1

    L,1

    O,3

    Because second values (Array1), after comma, is what we read from Array2. So, this means, "E" exist but in Array1 is on second position (Array1).

    I understand, you try to detect based on Array1, but the order need to be based on Array2 and give us the result.

    I hope make sense. But so far, you give me a lot help, i appreciate it. If this works better from your side, as paid work, let me know and contact me please via email: contactckz@odiusfly.com to discuss more.

    Thanks!

  • If you're trying to say that it counts as not existing if it comes at an earlier position in array 2 then that makes sense for E but how can H be 2 if it doesn't exist in the second array? I am going to give up on this for now, you seem to understand where I am going with the logic so you should be able to adjust it.

  • No, the "H" it's nothing to do with the result.

    To understand more:

    "Array1" = Question

    "Array2" = Answer

    So "Array1" after comma is our final result.

    From my latest example in the first position we write "E" so from the Array1 need to check from 0-Array1.width... if "E" exist or not.

    Ok, i will try to check it in deep your example. Thanks again for your help! :)

  • So "Array1" after comma is our final result.

    From my latest example in the first position we write "E" so from the Array1 need to check from 0-Array1.width... if "E" exist or not.

    This sounds like the reverse of what your original post asks. Checking if array 2 entries are in array 1, what ?

  • No, it's exactly with all examples i post until now.

  • Ok, to be more simplest. Let's forget (just example to explain you) the second value after comma. So let's imagine we have 3 arrays.

    Array1 = Question

    Array2 = Answer

    Array3 = Result

    So, Array1 values start from 0 - Array1.width

    This means, we start to detect from Array2:

    Array2(0) -> Start detect each value to all position of Array1.

    So from my latest example, Array1 have "E" to 1 position.

    And our answer (Array2) "Ε" was in 0 position of Array2.

    What means?

    Array3 (or Array 1 after comma, whatever) will give us result: 2

    I hope make sense now! If you check all my previous examples is exactly the same thing i try to explain all the time. Sorry for the misunderstanding.

    And some fast examples:

    Array1 => YES

    Array2 => YES

    Array3 => 111

    Array1 => YES

    Array2 => YSE

    Array3 => 122

    Array1 => YES

    Array2 => NES

    Array3 => 311

    Array1 => YES

    Array2 => ABC

    Array3 => 333

  • It’s simpler to look at with 1D arrays.

    So these two

    A =[ “a”, “b”, “c”]

    B =[“a”, “c”, “d”]

    Would give:

    C=[1,2,3]

    A:for each x
    — compare: A.at(A.curX)=B.at(A.curX)
    — — c: set at (a.curX) to 1
    — else
    — A: contains value B.at(A.curX)
    — — c: set at (a.curX) to 2
    — else
    — — c: set at (a.curX) to 3

    Doing it with 2D or 3D arrays may be similar, but I’m not up to working it out.

  • Thanks for your reply R0J0hound , i will check it!!! :)

  • Ok, to be more simplest. Let's forget (just example to explain you) the second value after comma. So let's imagine we have 3 arrays.

    Array1 = Question

    Array2 = Answer

    Array3 = Result

    So, Array1 values start from 0 - Array1.width

    This means, we start to detect from Array2:

    Array2(0) -> Start detect each value to all position of Array1.

    So from my latest example, Array1 have "E" to 1 position.

    And our answer (Array2) "Ε" was in 0 position of Array2.

    What means?

    Array3 (or Array 1 after comma, whatever) will give us result: 2

    I hope make sense now! If you check all my previous examples is exactly the same thing i try to explain all the time. Sorry for the misunderstanding.

    And some fast examples:

    Array1 => YES

    Array2 => YES

    Array3 => 111

    Array1 => YES

    Array2 => YSE

    Array3 => 122

    Array1 => YES

    Array2 => NES

    Array3 => 311

    Array1 => YES

    Array2 => ABC

    Array3 => 333

    This makes sense and I understood it as this and it was the results that my example gave but you said they were wrong and H should be 2 and E should be 3. Now you are saying E should be 2. There is confusion.

  • lionz please check my previous messages.

    "H" it's nothing to do with the result. "H" is on array1, is default values.

    Array1 is just a default values -> Question

    "E" exist on "array2" and "array1" but we detect always the values from array2 and their positions.

    If you check my latest latest post, check the examples i have. I'm not saying anything about "H" value. Let's write you again to be more simplest to you:

    Array1

    H

    E

    Array2

    E

    L

    This means:

    First value from Array2 is "E" so we give 2.

    Second value is "L" so we give 3. I give 3 not for "E" (Array1).

    Always check Array2. So in Array2 is "L" letter.

    I hope make sense now.

    Again, sorry for all this situation, maybe i needed to share more examples to be simplest.

    By the way thanks again!

  • R0J0hound

    Your example is great, but i want to ask you, how we can control the duplicates?

    A=[ “a”, “b”, “c” ]

    B=[ “b”, “b”, “a” ]

    To give:

    C=[ 3, 1, 2 ]

    Basicaly the point is as priority to check the same position if exist and give the value 1.

    Example1:

    A=[ “a”, “b”, “b”, “c” ]

    B=[ “b”, “b”, “d”, “b” ]

    To give:

    C=[ 2, 1, 3, 3 ]

    Example2:

    A=[ “a”, “b”, “b”, “c” ]

    B=[ “b”, “b”, “b”, “b” ]

    To give:

    C=[ 3, 1, 1, 3 ]

    Thanks again!!!

  • From my understanding (example1) duplicate has maximum number allowed based on first array as reference. So the third "b" in second array no longer valid since previous 2 "b" already occupied in correct order of existance thus return value '3'.

Jump to:
Active Users
There are 3 visitors browsing this topic (0 users and 3 guests)