Alice Community  

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

Reply
 
Thread Tools Display Modes
"When Key Is Typed" questions
Old
Jaker48895
Guest
 
Status:
Posts: n/a
Default "When Key Is Typed" questions - 01-17-2009, 10:25 AM

I'm making a airplane simulation and needed help with two things with the "when key is typed" command:

First off, i wanted the user to be able to turn on and off the engine with the same key and i couldn't figure out how to toggle the same key between two different methods (the engine on and off methods).

The second problem I'm having is to be able to only allow one key typed command to start a method before the other. In my case, i want the plane to takeoff only if the engine is on, which are both methods.
   
Reply With Quote
Old
Jaker48895
Guest
 
Status:
Posts: n/a
Default 01-18-2009, 04:40 PM

SOMEONE HELP!!!! ahhhh!!
i cant figure this out!
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 01-19-2009, 12:13 PM

Quote:
Originally Posted by Jaker48895 View Post
arrgghhhh!!
Boy you called that one right. Though it was going to be simple - but it gets caught up in when event whiles are evaluated vs. method whiles, loop checks, etc. - things that have (IMO) never been clearly explained for Alice. (Any explaination would be welcome - if anyone does understand it. )

Won't claim the attached is good code - but it does work and you can probably build on it - and knowing real helicopter pilots, l let you drive it into the ground if you want to.
Attached Files
File Type: a2w Start-Stop & Up-Down.a2w (438.9 KB, 70 views)
   
Reply With Quote
Old
vazin
Guest
 
Status:
Posts: n/a
Default 01-19-2009, 01:28 PM

Quote:
Originally Posted by DrJim View Post
Boy you called that one right. Though it was going to be simple - but it gets caught up in when event whiles are evaluated vs. method whiles, loop checks, etc. - things that have (IMO) never been clearly explained for Alice. (Any explaination would be welcome - if anyone does understand it. )

Won't claim the attached is good code - but it does work and you can probably build on it - and knowing real helicopter pilots, l let you drive it into the ground if you want to.
Very Nice. it is on top of my webpage
http://www.tech4dreams.com

Cheers
   
Reply With Quote
Old
Jaker48895
Guest
 
Status:
Posts: n/a
Default 01-20-2009, 05:41 PM

This is great Dr.Jim! That helicopter program was allot of help, although i have a question; you use a expression or something that is called "World.heli_running" and it is linked in allot of you commands. I wonder what this is, and how can i make one?

Thanks again!
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 01-21-2009, 11:09 AM

Quote:
Originally Posted by Jaker48895 View Post
... something ... called "World.heli_running" ... in a lot of you commands. I wonder what this is, and how can i make one?
That's a world level boolean variable and is pretty much the key to the whole thing. It is true when the motor is running and false when it's not. You can always test it in other programs and have them respond appropriately (i.e., take off or not).

Since it is a world level, it does not reset to the default value until the world stops (unlike a variable local to a method which resets to the default when the method completes).

To create it, go to the world properties box and click on "create new variable." Also a hint for debugging: It's very useful to play your program on a relatively small screen positioned so you can also see the variable in this box. The box will always show the variables current value as the program is running - and if you've made an error in your logic, it will be painfully obvious.

As a final note, this approach is also the reason I made the comment that the example really wasn't "good code." Hopefully Alice 3.0 will handle variable scope in a more OOP manner. I'll leave explaining what that means to others, however - just know this way isn't it - but it is the only way I know to handle this sort of thing in Alice 2.0.
Attached Images
File Type: jpg World-Level Variable.JPG (10.5 KB, 53 views)
   
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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.