Author Topic: No Key Pressed  (Read 5756 times)

0 Members and 1 Guest are viewing this topic.

Offline Tgooseman

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
No Key Pressed
« 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

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: No Key Pressed
« Reply #1 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
« Last Edit: April 19, 2011, 10:29:08 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: No Key Pressed
« Reply #2 on: April 19, 2011, 10:28:10 pm »
Welcome! May I suggest introducing yourself 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
« Last Edit: April 19, 2011, 10:32:53 pm by Runer112 »

Offline Tgooseman

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: No Key Pressed
« Reply #3 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?

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: No Key Pressed
« Reply #4 on: April 19, 2011, 10:29:43 pm »
oh sorry I just assumed BASIC. I didn't look at where it was...
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Tgooseman

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: No Key Pressed
« Reply #5 on: April 19, 2011, 10:31:14 pm »
My fault, should have been more specific.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: No Key Pressed
« Reply #6 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
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: No Key Pressed
« Reply #7 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: No Key Pressed
« Reply #8 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.




Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: No Key Pressed
« Reply #9 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.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: No Key Pressed
« Reply #10 on: April 20, 2011, 11:48:20 pm »
As far as I'm aware, the only way to do it is :Asm(76
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: No Key Pressed
« Reply #11 on: April 20, 2011, 11:50:26 pm »
The Stop command compiles to halt.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: No Key Pressed
« Reply #12 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

Offline Tgooseman

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: No Key Pressed
« Reply #13 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!

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: No Key Pressed
« Reply #14 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.
« Last Edit: June 08, 2011, 01:52:38 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s