Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Memory game problem
Old
keybasher
Member
 
Status: Offline
Posts: 17
Join Date: Jan 2013
Default Memory game problem - 05-05-2013, 06:37 PM

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:
Attached Files
File Type: a2w GameProject-JT.a2w (7.15 MB, 28 views)
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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.


(')>
   
Reply With Quote
Old
keybasher
Member
 
Status: Offline
Posts: 17
Join Date: Jan 2013
Default 05-06-2013, 12:31 AM

How do I create a global variable?
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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.


(')>
   
Reply With Quote
Old
keybasher
Member
 
Status: Offline
Posts: 17
Join Date: Jan 2013
Default 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)?
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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.


(')>
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 05-06-2013, 10:14 PM

Example's done. The comments explain most of the important stuff.
Attached Files
File Type: a2w Example.a2w (3.83 MB, 44 views)


(')>
   
Reply With Quote
Old
keybasher
Member
 
Status: Offline
Posts: 17
Join Date: Jan 2013
Default 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.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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.


(')>
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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