Compare two 2D Arrays

0 favourites
  • 6 posts
From the Asset Store
7 Dark mystery music ranging from a piano arrangement to full orchestral pieces.
  • Hello all.

    I have been using C2 for a while now and due to the awesome community here have been able to provide solutions to problems that have arisen in the past. Alas I think I may need to reach out with this one.

    I would like to compare the values in the corresponding cells in two Arrays. If they match up the user wins the game, if not a message appears for them to try again etc

    Here is what I have started with but I can't help but feel I am going about it in the wrong way?

    <img src="http://i.imgur.com/F6rNVJ6.png" border="0" />

    Am I on the right track?

  • Yep, you're on the right track. But the "curValue" from your "array_Solution" doesn't iterate at all through the array. Just replace the "array_Solution.curValue" with "array_Solution.At(array_Level_1.CurX,array_Level_1.CurY)". And add a "Stop loop" action, no need to continue the iteration when one error is found <img src="smileys/smiley2.gif" border="0" align="middle" />.

  • Thanks for your help. I have amended my event to what I understand you have said but it is still not working quite right. The "Win" action seems to come up no matter whether they match or not.

    Here what I have now.

    <img src="http://i.imgur.com/Q4gX5Kv.png" border="0" />

    When the Arrays have different values in the "Win" still comes up? I'm pretty sure it's just my ordering of the events and have tried different ways but to no avail. Any help would be appreciated. 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, your construction is somewhat right, but the else never fires (because an empty condition is always true). When you click the button, set the text to "Win", we assume the solution is correct unless proven otherwise. Change your condition to "not equal" and get rid of the else statement altogether. You don't need any extra sub-event under the loop. You should get something like this :

    <img src="http://img15.hostingpics.net/pics/262361arraycompare.png" border="0" />

  • Brilliant!

    Thank you very much for help. I appreciate it.

    I think I probably would never have thought about nesting the two event conditions there.

    Have a great day.

  • Thanks ! Always glad to help, and good day to you too ! <img src="smileys/smiley1.gif" border="0" align="middle" />

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