Compare two arrays and subtract identical values

  • Hi all. I've been working on a simple memory palace/recall game to practice using arrays. Problem is, I'm stuck and can't seem to figure out how to get unstuck. As always I'm probably overlooking something basic, but I could use a nudge in the right direction.

    Here's the basic flow of the game:

    1. Tap the screen and a random icon appears. Repeat several times.

    2. When a certain number of icons have been seen, go to the quiz screen.

    3. Quiz screen shows a grid of all the icons. User must tap to select the icons he or she saw in the previous screen.

    4. After the quiz screen, correct guesses will be added to an array for permanent storage.

    5. Next round is the same as the first, only now the icons that are shown do not repeat icons the user has correctly guessed.

    (.capx file to see the in-progress example. Ignore the incomplete sections, just stay on main-sheet)

    I've been using two arrays in my attempt to accomplish the last task:

    • Array1 (aIconPool) holds randomized numbers used to spawn icons.
    • Array2 (aSaved) holds a record of the correctly guessed icons.

    The idea is to subtract the contents of the second array from the contents of the first. My problem is I can't find a way to do this. The events pictured below do something similar, but incorrect:

    So, what's wrong with the above setup? I've tried various permutations of event ordering and nesting, but they're just as broken.

    Also, if my entire approach is too convoluted, feel free to tell me as such.


  • Try Construct 3


    Try Now Construct 3 users don't see these ads
  • I updated your checking event, that should work as intended now (at least I think)

    Not sure about the rest of the events, they will require some "work"


  • Heh, yeah, most of the other stuff in the file is scaffolding so I can test things. Long ways to go.

    I ran the updated capx and checked the debugger. The new method is pulling out a handful of entries, but not the ones I'm looking for. Here's what shows up in the debugger (array - index:value):

    aSaved - 0:0, 1:1, 2:2, 3:3, 4:4

    aIconPool: 0:1, 1:7, 2:9, 3:10, 4:11

    Right now, aSaved is loaded with dummy data 0-4 and aIconPool is loaded with dummy data 0-11. The output I'm looking for is to subtract aSaved from aIconPool, leaving aIconPool with the values 5-11.

    I'm going to keep experimenting/hitting my head against the wall until I figure out what's going on.

    Thanks for taking the time to check this out!

Jump to:
Active Users