Alice Community  

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

Reply
 
Thread Tools Display Modes
Using Variable to Toggle Colors
Old
alicenoob210
Guest
 
Status:
Posts: n/a
Default Using Variable to Toggle Colors - 11-03-2011, 09:40 PM

I'm working on a project that allows the user to change between five different color schemes. I figured variables and increments would allow me to do this, but no matter what I do, it only allows me to change colors once and that's it. I'll post the project file if you don't know what I'm talking about; I barely know what I'm doing (it's under the World.clickObject method).
Attached Files
File Type: a2w Project 2.a2w (4.94 MB, 8 views)
   
Reply With Quote
Old
waqar
Senior Member
 
Status: Offline
Posts: 51
Join Date: Sep 2011
Location: Pakistan
Default 11-03-2011, 10:00 PM

it is doing that bcz it is not going to the other if statments bcz every time a that method executes count reset to 0 and after increment by 1 it always come on 1 u have to make a hard coding for it and do that colour change statment in decending order it will definitely work i had that exp while i was making my shooting game and put 6 bullets and want to go opac 1 of them whenever i clicked on something frm thr i came to know abt it
   
Reply With Quote
Old
alicenoob210
Guest
 
Status:
Posts: n/a
Default 11-04-2011, 01:30 AM

Okay, so from what I gather, using variables wouldn't be a good idea. Playing with a dumbed down version of what I was working on, I found that if I use a list and have the program choose a random number from the list, I can toggle between multiple colors. The only problem is now, it would be kind of difficult for a user to anticipate what color will come up when they click x many times. It partly resolves the problem, though it again shifts the issue of being able to toggle between the preset choices in a predictable way.
   
Reply With Quote
Old
sfunk
Senior Member
 
sfunk's Avatar
 
Status: Offline
Posts: 1,112
Join Date: Mar 2011
Location: I don't know
Default 11-04-2011, 06:56 AM

Here, take a look at what I did with this world, it's very simple, I created a number variable, which I had increased every time the cylinder was clicked. then I had multiple if/else statments declaring if number_variable==(whatever number) the cube would change it's color. so after creating those methods you have to use the right type of events to place the methods into. I like using when the world starts and right clicking it to change it to "while the world is running" so the world constantly checks your if/else statements to decide what color the cube should be, and the last touch I made to it was once the number variable got to a certain number it would reset back to zero to be able to cycle through the colors again.
Attached Files
File Type: a2w Color_change_variables_used.a2w (178.0 KB, 12 views)


If you are stuck on a project, check out the tutorials I made here at this link:

http://alice.org/community/showthread.php?p=36778#post36778

There are lots of tutorials on it so far, including some youtube videos, check it out

Or..

Go to my youtube channel to check out my alice 2.2 tutorials I have there..

http://www.youtube.com/user/sfunk1992?feature=mhsn
   
Reply With Quote
Old
alicenoob210
Guest
 
Status:
Posts: n/a
Default 11-04-2011, 12:25 PM

Thanks! That worked perfectly.
   
Reply With Quote
increment
Old
walleyewilly
Junior Member
 
walleyewilly's Avatar
 
Status: Offline
Posts: 9
Join Date: Mar 2012
Location: youngstown
Default increment - 04-04-2012, 09:26 PM

Hi Sfunk:

I would like to use this increment for a project I am working on. I was just wondering where you got the increment method/function from without creating a variable for it. I did check out you tutorials, but did not see one on this particular subject. Thanks, Willy
   
Reply With Quote
Old
sfunk
Senior Member
 
sfunk's Avatar
 
Status: Offline
Posts: 1,112
Join Date: Mar 2011
Location: I don't know
Default 04-05-2012, 04:50 AM

Quote:
Originally Posted by walleyewilly View Post
Hi Sfunk:

I would like to use this increment for a project I am working on. I was just wondering where you got the increment method/function from without creating a variable for it. I did check out you tutorials, but did not see one on this particular subject. Thanks, Willy
You have to have a number variable to use increment or decrement methods


If you are stuck on a project, check out the tutorials I made here at this link:

http://alice.org/community/showthread.php?p=36778#post36778

There are lots of tutorials on it so far, including some youtube videos, check it out

Or..

Go to my youtube channel to check out my alice 2.2 tutorials I have there..

http://www.youtube.com/user/sfunk1992?feature=mhsn
   
Reply With Quote
variables
Old
walleyewilly
Junior Member
 
walleyewilly's Avatar
 
Status: Offline
Posts: 9
Join Date: Mar 2012
Location: youngstown
Default variables - 04-05-2012, 06:42 AM

Thank you. I see that now from your tutorial. For some reason when I loaded the lights example into Alice on my PC, it did not show the variable or the name change to world.my first method. Thanks, very helpful. Willy
   
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 ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.