How to make Memory Skill Game in Scratch | Card Matching Game in Scratch – Part 2 | Step-by-Step Coding

Scratch Game

Introduction: Memory Skill Game in Scratch

In this tutorial you'll learn how to make memory skill game in Scratch / card matching game in Scratch. This is a great beginner–to–intermediate project for scratch tutorial game, scratch programming games, and scratch game tutorials easy. You'll see how to use variables, costumes, lists, custom blocks, broadcasts, and graphical effects.

Whether you're teaching children, learning by yourself, or needing a project for Scratch club/class—this is a great game idea: create memory game in scratch / create matching game in scratch, building memory skill game in Scratch.

Why This Game Teaches Useful Skills

  • ✅ Logical thinking: deciding what happens when two cards match / don't match.
  • ✅ Use of variables: user control, matchOne, matchTwo, score, lives etc.
  • ✅ Use of lists: to store card identities / images / suits.
  • ✅ Use of custom blocks: for modularity ("make a list", "my card").
  • ✅ Scratch programming animation: graphical effects (color, brightness) to give feedback.

Memory Skill Game in Scratch: Step-by-Step Coding

Overview of the Card Matching Game in Scratch

Here's what your game will do:

  • On "green flag clicked", initialize variables: user control, matchOne, matchTwo, score, lives.
  • Display a grid of cards (sprites), all showing a "blank" face.
  • When user clicks a card (if control allows), flip it to show its hidden image / identity.
  • The user can flip two cards. After two are flipped, check: • If they match → correct: increment score, remove those cards. • If not match → incorrect: flip them back, decrement lives.
  • If score reaches a threshold → victory screen.
  • If lives reach zero → game over screen.

This matches very closely what the video shows.

Setting Up Your Scratch Project

If you have followed the Part -1 of this tutorial, you might already designed and setup your project. But, if you are missing anything:

Here are the initial steps, as per the video plus improvements:

  • Create sprites for all the cards. Usually you'll design one card sprite with multiple costumes (costume for each identity, plus a blank/hidden one).
  • Backdrops: you'll need at least three backdrops: the game board, victory, game over.
  • Variables: • `userControl` (or "user control") — yes / no value, to prevent too many clicks • `matchOne` — to store the identity (costume number) of the first flipped card • `matchTwo` — similarly for second card • `score` • `lives`
  • Lists: To store card identities / suits / the mapping of sprite → image.
  • Custom Blocks: e.g. "make a list", "my card" (from video) to help organizing repeated code.

Core Mechanics: Variables & their Roles

userControl Keeps track whether user is allowed to click cards (e.g. "yes" or "no"). Prevents buggy double clicks.
matchOne Stores the costume number of the first card clicked.
matchTwo Stores the costume number of second card clicked.
score Number of matched pairs made so far.
lives Number of attempts left.

Lists

  • Card list: a list of the hidden identities—so you can map each card sprite to an image / identity.
  • Could also maintain a list of which cards have already been removed or matched.

Custom Blocks

  • make a list: populates the card identity list (e.g. with duplicates, shuffle if needed).
  • my card: logic per individual card, e.g. what happens when clicked (flip, show image, check match).

Coding the Card Flip & Match Logic

Explanation:

  • `userControl` is a variable controlling whether the player can click cards.
  • `matchOne` and `matchTwo` store the first and second flipped cards (costume numbers).
  • `score` and `lives` track progress and remaining attempts.
  • `cardList` is a Scratch list variable holding the identities of the cards; you delete all items to start fresh each game.
  • `makeCardList` is a custom block you define that fills and shuffles the card identities.
when green flag clicked
    set [userControl v] to [yes]
    set [matchOne v] to [0]
    set [matchTwo v] to [0]
    set [score v] to [0]
    set [lives v] to [20]
    delete all of [cardList v] // clear the list before use
    // optionally call a custom block to populate the cardList
    call [makeCardList v]

Explanation:

Sprite (card) behavior: when this sprite clicked

when this sprite clicked
set userControl to "no"
if then
    // Show graphic effect
    repeat 10
        change color effect by 25
    end
    set brightness effect to 10
    // Switch costume to reveal hidden identity
    switch costume to (item (this sprite's index) of cardList) // or via costume number
    clear graphic effects
end

Managing which card is first or second clicked

if then
    set matchOne to (costume number)
    wait 0.2 seconds
    set userControl to "yes"
else
    set matchTwo to (costume number)
    // Now check match
    if then
        broadcast [correct]
    else
        broadcast [incorrect]
    end
end

Handling Correct / Incorrect Matches

If Correct

  • Increase `score` by 1
  • Broadcast "correct"
  • On receiving "correct": • Wait 1 second (so user sees the revealed cards) • Delete the matching clones/sprites or hide them so they are no longer clickable • Set `userControl` to "yes" so player can continue

If Incorrect

  • Decrease `lives` by 1
  • Broadcast "incorrect"
  • On receiving "incorrect": • Wait for a short delay (e.g. 0.5 seconds) so user sees cards before flipping back • Apply graphic effect (color / brightness) to flip back nicely • Switch costume back to "blank" (hidden) • Clear graphic effects • Set `userControl` back to "yes"

End–Game: Victory, Game Over

  • Check after each match or after each click (particularly after two cards flipped) whether `score` reaches the target (for example, total number of pairs) → if yes, change backdrop to "Victory" and hide sprites
  • Similarly, if `lives = 0`, change backdrop to "Game Over" and hide sprites

You wrap these checks inside conditionals triggered after the match logic.

Scenarios & Edge Cases in a Scratch Card Matching Game

1. Game Initialization

Scenario: When the green flag is clicked to start or restart the game.

Edge Case: The card list isn't cleared, causing duplicate cards or leftover data.

Solution: Always clear the card list and reset all variables before starting.

when green flag clicked
    delete all of [cardList v]
    set [score v] to [0]
    set [lives v] to [20]
    set [userControl v] to [yes]
    set [matchOne v] to [0]
    set [matchTwo v] to [0]
    call [makeCardList v] // populate and shuffle cards

2. User Control Management

Scenario: Prevent users from clicking more than two cards at once.

Edge Case: User clicks quickly and flips more than two cards.

Solution: Use the `userControl` variable to disable clicks while cards are being checked.

if <(userControl) = [yes]> then
    set [userControl v] to [no]
    // flip card logic
end

3. Handling Matching Cards

Scenario: Two flipped cards are identical.

Edge Case: Score isn't updated or matched cards are not removed.

Solution: Broadcast a "correct" message to trigger score update and remove matched cards. Delete matched card clones to remove from the stage.

if <(matchOne) = (matchTwo)> then
    broadcast [correct v]
    wait (1) seconds
    change [score v] by (1)
    delete this clone
else
    broadcast [incorrect v]
end

4. Handling Non-Matching Cards

Scenario: Two flipped cards don't match.

Edge Case: Cards stay flipped or user can't retry.

Solution: Broadcast an "incorrect" message to flip cards back after a short delay. Decrease `lives` by 1. Restore `userControl` to allow retry.

when I receive [incorrect v]
    wait (0.5) seconds
    switch costume to [back side] // flip card back
    clear graphic effects
    set [userControl v] to [yes]
    change [lives v] by (-1)

5. Clicking on the Same Card Twice

Scenario: User accidentally clicks the same card twice.

Edge Case: The game registers two clicks as different cards causing false match or errors.

Solution: Add a check to ignore clicks on the same card if it's already flipped. You can compare card identities or maintain a "clicked" state.

if > then
    // proceed with flip
end

6. Game Over Scenario

Scenario: Lives reach zero or player completes all matches.

Edge Case: The game does not end properly or sprites stay active.

Solution: Check lives and score after each match attempt. Change backdrop to "Game Over" or "Victory" accordingly. Hide all sprites or disable further interaction.

if <(lives) = [0]> then
    switch backdrop to [Game Over v]
    hide all sprites
    set [userControl v] to [no]
end
if <(score) = [total pairs]> then
    switch backdrop to [Victory v]
    hide all sprites
    set [userControl v] to [no]
end

7. Card List Integrity

Scenario: Card list items might get duplicated or corrupted.

Edge Case: Cards display wrong images or game logic breaks.

Solution: Clear the card list on every game start. Shuffle cards before assigning. Use consistent costume numbers matching list indices.

8. Graphics and Animation Effects

Scenario: Graphical effects glitch or accumulate indefinitely.

Edge Case: Cards disappear or effects overlap badly.

Solution: Clear graphic effects after every flip or reset. Use `repeat` loops with small increments for smooth effects.

repeat (10)
    change [color effect v] by (25)
    wait (0.05) seconds
end
clear graphic effects

9. Multiple Instances / Clones Handling

Scenario: Game uses clones for cards.

Edge Case: Clones are not properly deleted or updated.

Solution: Delete clones on correct matches. Reset variables when clones are created. Handle broadcasts to control all clones.

10. User Experience Enhancements

Scenario: Game feels slow or too fast.

Edge Case: Players get frustrated or bored.

Solution: Add a timer or countdown. Add sound effects on match / mismatch. Allow adjustable difficulty by changing lives or number of pairs.

Additional Feature Suggestions & Code

Add Sound Effects on Match/Mismatch

when I receive [correct v]
    play sound [correct chime v]

when I receive [incorrect v]
    play sound [wrong buzzer v]

Add Timer to Limit Gameplay

  • Create a variable `timer`
  • On green flag clicked, set `timer` to a starting value (e.g., 60 seconds)
  • Use a `forever` loop to decrement the timer every second
  • End game when timer reaches zero
when green flag clicked
    set [timer v] to [60]
    forever
        wait (1) seconds
        change [timer v] by (-1)
        if <(timer) = 0> then
            broadcast [gameOver v]
            stop [all v]
        end
    end

Shuffle Card List (Custom Block)

define makeCardList
    delete all of [cardList v]
    // add pairs of cards (e.g., 1 to 6 twice)
    repeat (6)
        add (repeatIndex) to [cardList v]
        add (repeatIndex) to [cardList v]
    end
    // shuffle the list randomly
    repeat (length of cardList)
        set [index1 v] to (pick random 1 to (length of cardList))
        set [index2 v] to (pick random 1 to (length of cardList))
        set [temp v] to (item (index1) of [cardList v])
        replace item (index1) of [cardList v] with (item (index2) of [cardList v])
        replace item (index2) of [cardList v] with (temp)
    end

Conclusion: Memory Skill Game in Scratch

Creating a card matching game in Scratch is more than just a fun project — it's a powerful way to boost logical thinking, enhance problem-solving skills, and get hands-on with real programming concepts like variables, conditionals, broadcast messaging, and clone management.

In this step-by-step tutorial, we've covered everything from:

  • Setting up the game environment and logic
  • Managing user interaction with variables like `userControl`, `matchOne`, and `matchTwo`
  • Using broadcasts to handle matching/mismatching events
  • Adding engaging visual and sound effects
  • Handling edge cases like rapid clicks or mismatched logic
  • Ending the game gracefully with a win or lose screen

By following along, you've learned how to create a Scratch memory skill game that is fun, challenging, and totally customizable. Whether you're a beginner or teaching kids how to code, this project is a perfect introduction to Scratch programming and game development.

Call to Action

  1. Don't forget to check out the full video tutorial: How to make a Card Matching Game in Scratch | Memory skill game in Scratch – Part 2 – Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. Subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we're passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links