Alice Community  

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

Reply
 
Thread Tools Display Modes
The Binary game
Old
Kelrizzo
Junior Member
 
Kelrizzo's Avatar
 
Status: Offline
Posts: 5
Join Date: Feb 2013
Location: Seattle
Default The Binary game - 04-25-2013, 03:40 PM

I'm working my way through the Alice Textbook and I think my brain is not making connections with how variables get assigned to objects.

In the game from the text, you have the three switches. Each switch is assigned a 0 or 1. You now have a binary number (000, 001, 010, 011, etc). In my example the switch being up represents 1 and the switch begins in the up position. If you get the number correct, a light bulb lights up.

I have a world level variable for the Object switch so I can modify which switch I'm using, and I also have a world level variable to hold the random number.

I really think I'm going about this the wrong way, but it's taking me quite long to do so I figured I'd stop desk/head and ask for help.
   
Reply With Quote
Simple
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Simple - 04-25-2013, 07:51 PM

Don't know about the book, but
Click on any object.
Click the properties tab in details.
Click the Create Variable button and make one for that object.
   
Reply With Quote
Old
Kelrizzo
Junior Member
 
Kelrizzo's Avatar
 
Status: Offline
Posts: 5
Join Date: Feb 2013
Location: Seattle
Default 04-26-2013, 12:07 PM

Oh I understand the physical steps to make a variable. Maybe I'm too tired to make sense I was talking about the theoretical...when to use a variable versus a parameter.

I'm going to work on the project again now so I may get somewhere on my own, but I need to assign a random value 0 or 1 to each of the three switches. The user guesses what each switch is by flipping it up or down. Up represents 1, down represents 0. So you have a binary number with 3 digits.

If you guess the right number, the lightbulb goes on.
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 04-27-2013, 12:10 PM

Quote:
Originally Posted by Kelrizzo View Post
Oh I understand the physical steps to make a variable. Maybe I'm too tired to make sense I was talking about the theoretical...when to use a variable versus a parameter.

I'm going to work on the project again now so I may get somewhere on my own, but I need to assign a random value 0 or 1 to each of the three switches. The user guesses what each switch is by flipping it up or down. Up represents 1, down represents 0. So you have a binary number with 3 digits.

If you guess the right number, the lightbulb goes on.
If I understand correctly you have a target value from 0 to 7 and you want to use this to tell when the switches are in the correct position. Each switch can either be off-0 or on-1 what you may be missing is the binary math here. Using three bits in binary I can represent any number from 0 to 7. Here is the binary:

000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

Why did I go through all that? Well since each switch can be either a 0 or a 1 we need to scale the value of two of the switches to create the three binary digits above.
So your switches value would be something like "set currentVal = sw1 + sw2 * 2 + sw3 *4"
Now you have converted the individual switches into one value between 0 and 7.

PS the values 2 and 4 in the conversion come from binary positional notation. If you want to look this up, start with decimal positional notation. This will make the concept clear and then see how it would be done for numbering systems in other bases.

Mark
   
Reply With Quote
Old
Kelrizzo
Junior Member
 
Kelrizzo's Avatar
 
Status: Offline
Posts: 5
Join Date: Feb 2013
Location: Seattle
Default 04-27-2013, 01:43 PM

Ahhhh ok. It's all a matter of setting up a way in which Alice can understand what you are trying to accomplish. Thank you!

As I was muddling through this, it came to mind that I would like a way to indicate whether the switch was on or off (1 or 0), so I developed a light system and named the method "moveSwitch" with a parameter "whichSwitch".

I had it working perfectly...then I broke it. I actually only had it working for the one switch, but of course I want it to work for all the switches.

HTML Code:
<del>Two issues:
1) When I tell the switch to move forward simply by playing with the object alone, the "turn forward" command works the way I wish it to.  When I call it with my method, it no longer turns in that way.  I've played with several "as seen by" commands, but to no avail.

2) The light was changing from green to red, and back to green, then stopped working as I added the parameter.  

What did I do to break it?</del>
I'll keep playing with it, maybe I will figure it out, and will let you know if I do. In the meantime, I will also begin working on the binary portion.

EDIT: Fixed it. Now to apply it to the other lights and switches then incorporate the binary.

EDIT2: Applied to all lights and it works. Now the last step. Thanks for all the assistance.

EDIT3: Yeay Got it! Thanks
Attached Files
File Type: a2w Binary Game.a2w (292.7 KB, 11 views)

Last edited by Kelrizzo; 04-27-2013 at 03:44 PM.
   
Reply With Quote
I have a suggestion for you.
Old
KentuckyFriedJesus
Junior Member
 
KentuckyFriedJesus's Avatar
 
Status: Offline
Posts: 8
Join Date: Mar 2012
Location: 'Merica
Default I have a suggestion for you. - 05-01-2013, 12:52 PM

Since your game is a binary game, I have a message for you from me via binary language:

01000010 01100101 00100000 01110011 01110101 01110010 01100101 00100000 01110100 01101111 00100000 01100100 01110010 01101001 01101110 01101011 00100000 01111001 01101111 01110101 01110010 00100000 01001111 01110110 01100001 01101100 01110100 01101001 01101110 01100101 00101110


I love fried watermelon chicken-aid.

Last edited by x2495iiii; 05-01-2013 at 02:28 PM. Reason: Be nice.
   
Reply With Quote
Reply


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.