Alice Community  

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

Reply
 
Thread Tools Display Modes
One key turn something on and off?
Old
DemonBoy113
Member
 
Status: Offline
Posts: 44
Join Date: Nov 2009
Default One key turn something on and off? - 02-20-2010, 09:57 PM

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
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 02-20-2010, 11: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.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
DemonBoy113
Member
 
Status: Offline
Posts: 44
Join Date: Nov 2009
Default 02-21-2010, 06:26 PM

im not quite understanding this so could i have an example. that would help me
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 02-21-2010, 07:38 PM

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.
Attached Files
File Type: a2w NightVision.a2w (169.6 KB, 24 views)


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
DemonBoy113
Member
 
Status: Offline
Posts: 44
Join Date: Nov 2009
Default 02-21-2010, 10: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.
   
Reply With Quote
Old
zonedabone
Senior Member
 
zonedabone's Avatar
 
Status: Offline
Posts: 577
Join Date: Nov 2008
Location: In the interwebs
Default 02-22-2010, 09: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.


'Apple Macintosh' - An anagram of 'Complaints Heap'

M.A.C.I.N.T.O.S.H. - Machine Always Crashes, If Not, The Operating System Hangs.

You're *such* a mac person.
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 02-23-2010, 06:13 PM

Quote:
Originally Posted by Dameria View Post
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.

That is exactly the way i do it


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
Reply With Quote
Old
zonedabone
Senior Member
 
zonedabone's Avatar
 
Status: Offline
Posts: 577
Join Date: Nov 2008
Location: In the interwebs
Default 02-28-2010, 03:19 PM

Jedi, you keep on saying "I could have." We all know that you could have. We all can. Please don't keep on doing this.


'Apple Macintosh' - An anagram of 'Complaints Heap'

M.A.C.I.N.T.O.S.H. - Machine Always Crashes, If Not, The Operating System Hangs.

You're *such* a mac person.
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 02-23-2010, 06:11 PM

Quote:
Originally Posted by DemonBoy113 View Post
im not quite understanding this so could i have an example. that would help me

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


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
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 ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.