### Author Topic: The Smallest Axiom Ever (Optimized GetKey routine)  (Read 2678 times)

0 Members and 1 Guest are viewing this topic.

#### Binder News

• Posts: 785
• Rating: +46/-3
• Zombie of Tomorrow
##### The Smallest Axiom Ever (Optimized GetKey routine)
« on: May 22, 2011, 10:11:11 pm »
First, this Axiom is super-small. Compiled, it's about 60 bytes.
Anyways, it is an optimized form of GetKey when you only want ONE of the four arrow-keys.
For example, if I'm making a maze game where the player can only move up, down, left, or right, but not 2 at once, this would be perfect.
The command is the Zoom In token, with no modifiers.
Also, the version for your calc is a program. If you have it in RAM when you compile something using it, Axe will convert it to an Appvar, and put it into archive. You can then delete the program.
Spoiler For userbars:

Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:

#### calc84maniac

• eZ80 Guru
• Coder Of Tomorrow
• LV11 Super Veteran (Next: 3000)
• Posts: 2896
• Rating: +467/-17
##### Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #1 on: May 22, 2011, 10:16:00 pm »
Hmm, this routine doesn't seem to really check that only one of the keys is pressed. For example, if you pressed all the arrow keys at once, it would return 1.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

#### Binder News

• Posts: 785
• Rating: +46/-3
• Zombie of Tomorrow
##### Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #2 on: May 22, 2011, 10:24:49 pm »
Yes, but the purpose of the routine is that you only want one of the keys. The way I designed it means that the first one happens to be the down key, but it could be redesigned to allow for a different key to be checked first.
Spoiler For userbars:

Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:

#### jacobly

• Posts: 205
• Rating: +161/-1
##### Re: The Smallest Axiom Ever (Optimized GetKey routine)
« Reply #3 on: January 22, 2012, 10:50:23 pm »
I believe this is now the smallest axiom ever.

The token for this axiom is Zoom Out. It returns what arrow keys are currently pressed. As an added bonus, opposite keys cancel each other out. For example, if both the left and right keys are pressed, then this axiom will return that neither key is pressed. This is useful if pressing a key results in a lot of computation, and pressing opposite keys results in nothing happening.

(In the following example, e is the euler e.)
Code: [Select]
#Axiom(SpeedKey)Zoom Out→AIf Ae7.down key pressedEndIf Ae6.left key pressedEndIf Ae5.right key pressedEndIf Ae4.up key pressedEnd
This axiom can also be used to easily check for 8 directions.
Code: [Select]
#Axiom(SpeedKey)Zoom Out→AIf A=1.southElseIf A=2.westElseIf A=3.south westElseIf A=4.eastElseIf A=5.south eastElseIf A=8.northElseIf A=10.north westElseIf A=12.north eastEnd
« Last Edit: June 28, 2012, 05:36:23 pm by jacobly »

#### Deep Toaster

• So much to do, so much time, so little motivation