Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Tgooseman on April 19, 2011, 10:21:09 pm

Title: No Key Pressed
Post by: Tgooseman on April 19, 2011, 10:21:09 pm
What is the syntax for running a loop while no key is being pressed?  What command(s) would be used to basically recognize a key is not being pressed, then run the code? I am making a game similar to helicopter, and it would make it so the helicopter would fall when no key is pressed.  I know it would most likely involve the getKey command, but I can't figure out how to manipulate it. 

P.S this is my first post on Omnimaga :D
Title: Re: No Key Pressed
Post by: ruler501 on April 19, 2011, 10:25:22 pm
I use to have code to do this on my 84 emulator before I accidently Ram cleared it with an OS update.

It was something like
Code: [Select]
:0->A
:While A = 0
:getKey -> A

I'm assuming your using TI-BASIC on 84/83/82

Welcome to Omnimaga post an intro topic an you'll get some peanuts
Title: Re: No Key Pressed
Post by: Runer112 on April 19, 2011, 10:28:10 pm
Welcome! May I suggest introducing yourself (http://www.omnimaga.org/index.php?board=10.0) so we can learn a little bit about you and all say hi?

To answer your question, I believe you want the getKey(0) command. Normally, getKey(number) is used to check if a specific key corresponding to that key code is pressed. But if you enter a zero, it will instead check if any key is pressed. To create a loop that repeats as long as no key is pressed, I would suggest the following:

Code: [Select]
While 1             .Endless loop...

EndIf getKey(0)     .Until a key is pressed
Title: Re: No Key Pressed
Post by: Tgooseman on April 19, 2011, 10:28:33 pm
Oh i mean in AXE, sorry I thought i posted in the AXE part of the forum! By any chance do you know how in AXE?
Title: Re: No Key Pressed
Post by: ruler501 on April 19, 2011, 10:29:43 pm
oh sorry I just assumed BASIC. I didn't look at where it was...
Title: Re: No Key Pressed
Post by: Tgooseman on April 19, 2011, 10:31:14 pm
My fault, should have been more specific.
Title: Re: No Key Pressed
Post by: ruler501 on April 19, 2011, 10:33:45 pm
You posted in the Axe section you had the right to expect that we'd help you with Axe code
Title: Re: No Key Pressed
Post by: willrandship on April 19, 2011, 10:48:10 pm
getkeyr (the same as dispgraphr) does the same without a loop, but it doesn't use 2nd or Alpha the same way, since it's the OS input routine. It also has a different keymap.
Title: Re: No Key Pressed
Post by: Deep Toaster on April 20, 2011, 06:17:47 pm
getkeyr (the same as dispgraphr) does the same without a loop, but it doesn't use 2nd or Alpha the same way, since it's the OS input routine. It also has a different keymap.

Yep, it basically waits for a key combination such as MATH, 2ND+MATH, ALPHA+MATH, etc.
Title: Re: No Key Pressed
Post by: FloppusMaximus on April 20, 2011, 11:20:36 pm
Is there an Axe command to halt the CPU?  It's a good idea to do so while you're waiting for user input.
Title: Re: No Key Pressed
Post by: AngelFish on April 20, 2011, 11:48:20 pm
As far as I'm aware, the only way to do it is :Asm(76
Title: Re: No Key Pressed
Post by: calc84maniac on April 20, 2011, 11:50:26 pm
The Stop command compiles to halt.
Title: Re: No Key Pressed
Post by: shmibs on April 20, 2011, 11:50:44 pm
runer's syntax is correct. however, if you're making a helicopter game it would make a bit more sense (and probably make the code more legible later on when you return to it and can't for the life of you figure out what's going on) to leave the code in a helicopter crash or getkey(15) terminated loop with your gravity code executed every cycle and your 'helicopter moves upward' (::)) code in an If getkey(4):execute gravity code:End loop, or alternatively have an infinite loop containing If getkey(4):helicopter goes up code:else:gravity code:End
Title: Re: No Key Pressed
Post by: Tgooseman on April 22, 2011, 02:13:09 am
Alright thanks for the suggestions i've got gravity figured out, next up, collision detection. Wish me luck!
Title: Re: No Key Pressed
Post by: Hayleia on June 08, 2011, 01:52:22 pm
Then good luck !
Also, "getkey(0)" returns 1 if a key is pressed and returns 0 if no key is pressed (correct me if it is the exact contrary). Maybe it will help. You could use "Repeat getkey(0)" for example. I use it everywhere ;D.
Title: Re: No Key Pressed
Post by: ztrumpet on June 08, 2011, 03:19:16 pm
Also, "getkey(0)" returns 1 if a key is pressed and returns 0 if no key is pressed (correct me if it is the exact contrary).
I'm not 100% sure here, but I think if a key is pressed it returns a non-zero number, not necessarily one.
Title: Re: No Key Pressed
Post by: Deep Toaster on June 08, 2011, 04:10:17 pm
Yep, it's some non-zero number depending on what key(s) you pressed, or zero if you didn't press any key. Repeat getKey(0) and things like that work.