How do I find the second repeated value in an array (not first or last value)?

  • I have an array(X) filled with numbers.

    Example

    1 5 7 8 15 2 20 15 7 15 55 15 25

    The array will add or take away cells which change the location of the number

    Example

    1 5 32 7 8 15 2 17 20 15 7 15 55 72 15 25

    Let's say I wanted to grab the location of the second 15. I know how to access the first and last. How would I do locate the second, or in some cases the third (but not last)?

  • I think we need some context here.

    Usually with arrays you are looping through them, or if you use them statically then you are just referencing the array positions with CONSTANTS.

    If you want to find the first 15, loop until you get 15

    to find others you would need a second local variable that counts how many you found, you stop at the desired one with Stop Loop.

  • Jobel is right.

    Local variables Tracker = 0;

    For each array X elements

    - if array.curValue = 15

    -- Add 1 to Tracker

    -- if Tracker = 2

    ---- array.curX = SECOND_15_LOCATION

    ---- Stop Loop

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for everyones help! It worked:)

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