Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   "When Key Is Typed" questions (http://www.alice.org/community/showthread.php?t=2138)

Jaker48895 01-17-2009 11:25 AM

"When Key Is Typed" questions
 
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.

Jaker48895 01-18-2009 05:40 PM

SOMEONE HELP!!!! ahhhh!! :confused:
i cant figure this out!

DrJim 01-19-2009 01:13 PM

1 Attachment(s)
[QUOTE=Jaker48895;8446]arrgghhhh!! :confused: [/QUOTE]

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. :mad:)

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.

vazin 01-19-2009 02:28 PM

[QUOTE=DrJim;8454]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. :mad:)

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.[/QUOTE]

Very Nice. it is on top of my webpage
[url]http://www.tech4dreams.com[/url]

Cheers

Jaker48895 01-20-2009 06: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!

DrJim 01-21-2009 12:09 PM

1 Attachment(s)
[QUOTE=Jaker48895;8478] ... something ... called "World.heli_running" ... in a lot of you commands. I wonder what this is, and how can i make one?[/QUOTE]

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[I] isn't[/I] it - but it is the only way I know to handle this sort of thing in Alice 2.0.


All times are GMT -5. The time now is 03:27 PM.

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