Alice Community

Alice Community (
-   How do I...? (
-   -   Memory game problem (

keybasher 05-05-2013 06:37 PM

Memory game problem
1 Attachment(s)
I'm building a memory game for a class I'm in, in which the user flips over two cards to see if they match. If they do match, they stay face up. However, I can't seem to figure out how to make them flip back over automatically if they don't. Is there any way this can be done?

Here's what I have so far:

x2495iiii 05-05-2013 09:23 PM

You'll need to use global variables if you want an event to check the value of the cards.

keybasher 05-06-2013 12:31 AM

How do I create a global variable?

x2495iiii 05-06-2013 02:57 AM

-click the "world" item in the item list on the left of the screen to select it

-click the properties tab in the center-left of the screen

-click the "create variable" button at the top of the properties menu

Global variables can be accessed by any method or event, so they're best to use for beginning programs.

keybasher 05-06-2013 01:20 PM

I see. I've created some global variables now, but how does this answer my original question (from the first post)?

x2495iiii 05-06-2013 09:21 PM

You need to replace all the references to the old memoryCard1 and memoryCard2 variables with references to the new global variables you made.

With that, you can add some logic to the end of the event (near the gong sound effect) that would turn the cards around.

The only problem is that, as it is, you'd need another huge nested if/else statement to turn the cards back around.

I'm working on an example that uses parameters and variables to eliminate the use of nested if/else statements.

x2495iiii 05-06-2013 10:14 PM

1 Attachment(s)
Example's done. The comments explain most of the important stuff.

keybasher 05-07-2013 12:38 AM

Thank you so much. I learned a lot from that. I would never have thought of that at all. You clearly have more experience with Alice than I do and I hope one day I can program as well as you.

x2495iiii 05-07-2013 01:41 PM

Glad to help.

If you have any questions about the concepts used, let me know.

EDIT: Forgot to mention, you'll still need to add something that tells the user when they've won.

All times are GMT -5. The time now is 06:29 PM.

Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.