Copying an item in a list of lists to another item in the same list of lists

Here is how I would code this:

  • Keep global variables:

    • A_Flipped: -1 or the Sprite that was flipped in set A
    • B_Flipped: -1 or the Sprite that was flipped in set B
  • Keep global lists:

    • A_Sprites (5 components, fixed)
    • B_Sprites (")
    • A_Images (initially empty each round, to be filled with 5 image file names soon)
    • B_Images (")
    • All_Pics (All images that could be used in Sprites listed above)
  • To reset a round:

    • set A_Flipped to -1
    • set B_Flipped to -1
    • set A_Images to make a list(select random item from All_Pics)
    • set B_Images to copy of A_Images
    • while length of list(A_Images) < 5 do
      • set local temp_image to random item from list All_Pics
      • if not(temp_image is in list A_Images) and not(temp_image is in list B_Images) then add temp_image to list A_Images
    • while length of list(B_Images) < 5 do
      • set local temp_image to random item from list All_Pics
      • if not(temp_image is in list A_Images) and not(temp_image is in list B_Images) then add temp_image to list B_Images
    • set list A_Images to shuffle(A_Images)
    • set list B_Images to shuffle(B_Images)

When a sprite is touched:

  • If (touched sprite is in A_Sprites list) and (A_Flipped = -1) then
    • set A_Flipped to sprite component
    • set index i to index in list A_Sprites of touched component
    • set Picture of A_Flipped component to (select item i from list A_Images)
  • If (touched sprite is in B_Sprites list) and (B_Flipped = -1) then
    • set B_Flipped to sprite component
    • set index i to index in list B_Sprites of touched component
    • set Picture of B_Flipped component to (select item i from list B_Images)
  • if (A_Flipped is in list A_Sprites) and (B_Flipped is in list B_Sprites) then
    • if A_Flipped.Picture = B_Flipped.Picture then you have a match, else a mismatch
    • unflip the two sprites:
      • set their images to card backs
      • set A_Flipped back to -1
      • set B_Flipped back to -1

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

1 Like