Alice Community  

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

Reply
 
Thread Tools Display Modes
Help with an if/else statement...
Old
dragongirl411
Guest
 
Status:
Posts: n/a
Default Help with an if/else statement... - 05-02-2010, 06:37 PM

Hi all.

I have say 20 objects in my Alice world, 17 of which are cubes. I'm trying to write a code in Alice that does this:
If all cubes are blue then call a method.

For some reason I'm having trouble. In world/properties I created a variable that contains a list of all the cubes. Then I created an If/Else statement and brought in one of the cubes as a placeholder. But when I drag my object variable of all cubes to the cube placeholder, it won't let me.

Any ideas? I appreciate any help on this.
   
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-02-2010, 08:19 PM

Odd. If it's an object list and the placeholder is an object as well, there shouldn't be any problems. Post your world as an attachment and I'll see what I can do.


(')>
   
Reply With Quote
Old
dragongirl411
Guest
 
Status:
Posts: n/a
Default 05-02-2010, 08:41 PM

Here's my Alice file.

For the Qbert object, there is a method called universalJump. It is inside this method that I'm trying to create my allCubesBlue statement. For world properties, I created a list variable called allCubesBlue to include all 17 cube objects.

Like I said before, I'm trying to get something like this:
If all cubes are blue, then call the endGameWin method.

Thanks for your help.
Attached Files
File Type: a2w Qbert_r3.a2w (2.89 MB, 3 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-02-2010, 09:02 PM

K, I'm checking it out now. I don't have too much time to look at it, though, so sorry in advance if I can't fix it immediately.


(')>
   
Reply With Quote
Old
dragongirl411
Guest
 
Status:
Posts: n/a
Default 05-02-2010, 09:05 PM

Oh I don't want you to fix it, I'm just fishing for suggestions or someone to point me in the right direction
   
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-02-2010, 09:20 PM

Oh. Well, I sorta fixed it already. The problem is that you need a function that addresses all the items in the list simultaneously and tests their colors to see if they're all blue. Alice doesn't have such a function, so you have to create a makeshift one yourself. I have the world, but I'll only post it if you get stuck. To point you in the right direction, I used a boolean variable, a for all in order, and two if/else ifs to make a working function.

Good luck.


(')>
   
Reply With Quote
Old
dragongirl411
Guest
 
Status:
Posts: n/a
Default 05-02-2010, 09:59 PM

Ok, I've tried what you suggested but I don't really understand how it all fits together to make the function, and what value that function returns.
   
Reply With Quote
Old
dubastot
Senior Member
 
dubastot's Avatar
 
Status: Offline
Posts: 661
Join Date: Apr 2009
Location: Two Steps From Hell
Default 05-02-2010, 10:11 PM

Here, let me see what kind of an example I can make.


I'm a web developer/ designer now.
   
Reply With Quote
Old
dubastot
Senior Member
 
dubastot's Avatar
 
Status: Offline
Posts: 661
Join Date: Apr 2009
Location: Two Steps From Hell
Default 05-02-2010, 10:23 PM

I know this is crude, but I really don't feel like working on alice right now. Anyways, this should give you a rough idea.
Attached Files
File Type: a2w Example for stuff.a2w (169.3 KB, 4 views)


I'm a web developer/ designer now.
   
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-02-2010, 11:56 PM

Well here's what I did to make it work. The only glitch I noticed when i tested it was that once, when I clicked on a block that wasn't next to Q-Bert, it generated a win when it shouldn't have. Not sure how or why that happened, but then I didn't really look into it (if the glitch persists, you can figure out a way to counteract it).

Nice job recreating a classic, by the way.
Attached Files
File Type: a2w Qbert_r3.a2w (2.90 MB, 4 views)


(')>
   
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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.