Omnimaga
Calculator Community => TI Calculators => Axe => Topic started 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
-
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
: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
-
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:
While 1 .Endless loop...
EndIf getKey(0) .Until a key is pressed
-
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?
-
oh sorry I just assumed BASIC. I didn't look at where it was...
-
My fault, should have been more specific.
-
You posted in the Axe section you had the right to expect that we'd help you with Axe code
-
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.
-
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.
-
Is there an Axe command to halt the CPU? It's a good idea to do so while you're waiting for user input.
-
As far as I'm aware, the only way to do it is :Asm(76
-
The Stop command compiles to halt.
-
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
-
Alright thanks for the suggestions i've got gravity figured out, next up, collision detection. Wish me luck!
-
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.
-
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.
-
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.