Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Using Variable to Toggle Colors (http://www.alice.org/community/showthread.php?t=7498)

alicenoob210 11-03-2011 09:40 PM

Using Variable to Toggle Colors
 
1 Attachment(s)
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 :p (it's under the World.clickObject method).

waqar 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

alicenoob210 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.

sfunk 11-04-2011 06:56 AM

1 Attachment(s)
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.

alicenoob210 11-04-2011 12:25 PM

Thanks! That worked perfectly.

walleyewilly 04-04-2012 09:26 PM

increment
 
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

sfunk 04-05-2012 04:50 AM

[QUOTE=walleyewilly;47836]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[/QUOTE]

You have to have a number variable to use increment or decrement methods

walleyewilly 04-05-2012 06:42 AM

variables
 
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


All times are GMT -5. The time now is 08:09 AM.

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