Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   One key turn something on and off? (http://www.alice.org/community/showthread.php?t=3956)

DemonBoy113 02-20-2010 08:57 PM

One key turn something on and off?
 
im making a spy game, and i want to make it so that one key that will turn night vision goggles on and off. how would i do that if i can

Dameria 02-20-2010 10:37 PM

well you can just make a boolean variable within the world (do not make it in the method itself) and call it nightVisionOn. It could initially be turned to false, but then when you click a button (lets say space) it runs the method enableNightVision.

Within this method you can have an if/else statement saying (if(nightVisionOn)) and then in that if you make the method to turn it off, and then in the (else) you can have the method to turn night vision on. At the end of the if statement, you simply add a command to turn nightVisionOn == false, and then at the end of the else statement have nightVisionOn == true.

Now every time you run the method, depending if nightVisionOn is true or false, it will have a distinct method, but both will be triggered by pressing the space bar. If you need more help, just ask and I will create a world with the example.

DemonBoy113 02-21-2010 05:26 PM

im not quite understanding this so could i have an example. that would help me

Dameria 02-21-2010 06:38 PM

1 Attachment(s)
Ok here is an example I made. It starts out as night with night vision off, but then when you click space the night vision goes on. When you click space again, the night vision turns off.

Click on the variables tab in "world" to see the boolean I created, and in the method, I made the boolean change to either true or false so that the next time the method is called it will do the opposite. The boolean is like a switch that gets turned on and off.

DemonBoy113 02-21-2010 09:09 PM

well thats cool it works now thank you Dameria. btw i also used your crosshair idea that i randomly found and that helped.

zonedabone 02-22-2010 08:22 PM

A simpler way to set this up would be when space is typed, set your night vision variable to not(your night vision variable. First just have it set the variable to itself, and then right click the variable in the second part of the command, and set it to logic>not variable. This combines the statements, and saves memory as well as screen space.

Dameria 02-23-2010 05:07 AM

Can you repost the world showing what you mean please? You can just edit the NightVision world and upload that if you want.

zonedabone 02-23-2010 05:07 PM

1 Attachment(s)
Here it is! :D

Dameria 02-23-2010 05:10 PM

Yes I guess you could do it that way, thanks I learned something new.

jediaction 02-23-2010 05:11 PM

[QUOTE=DemonBoy113;17327]im not quite understanding this so could i have an example. that would help me[/QUOTE]


If i read this earlier i could of made an example to


All times are GMT -5. The time now is 03:10 AM.

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