How do I update an array element based an another array?

0 favourites
  • 3 posts
From the Asset Store
Fantasy Game includes more than 600 sound effects inspired by hit computer games like World of Warcraft and Diablo.
  • I have these two arrays, namely ArrayForSequencying and ArrayForMatchGame.

    I need to replace the the 2nd value in ArrayForMatchGame based on the 3rd value in Array for Sequencing

    if the 1st value of ArrayForMatchGame <> 0 and is equal to the 2nd value in ArrayForSequencing:

    ArrayForSequencing

    0 with 2, 5, 1

    1 with 3, 4, 1

    2 with 4, 1, 2

    3 with 5, 2, 2

    4 with 6, 3, 3

    and so on

    ArrayForMatchGame

    0 with 0,0 should be left as is

    1 with 3,0 should become 3, 3

    2 with 5,0 should become 5, 1

    3 with 2,0 should become 2, 2

    4 with 1,0 should become 1, 2

    5 with 4,0 should become 4, 1

    and so on

    I have tried various combinations of "For each XY element" or "For each X element" "For" loops but I am still struggling to get it right. (I tried pasting the image to this post, but nothing comes out when I page between the img placeholders.) Thanks in advance.

  • To save yourself from endless looping, just use a lookup table.

    In c2, the most easy lookup table is a dictionary.

    But, lets do it with the second best candidate: a 1D array.

    Using a 1D array, we can use .....

    The condition > Array > Contains value (value)

    The expression > Array.IndexOf( value )

    ..... to get an the index of a found value in return

    Both scan the whole array, and that is not what we need, so i made a 1D lookup table (event 22) with only the values that they are allowed to scan (the 2nd value in ArrayForSequencing)

    From there it is easy, as you see :

    https://www.dropbox.com/s/qpclzk430wxf3 ... .capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you very much.

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