Optimal Method of Checking Keypresses on TI-89
Asked Answered
L

2

6

for an experiment I decided to program a little game into my TI-89 using the built in program editor, however I cannot figure out an optimal method of getting keystrokes without significant delay. Currently I have:

Prgm

70→xpos
70→ypos

Loop

If getKey()=340 Then
xpos+3→xpos
PxlCrcl ypos,xpos,5,1
EndIf

If getKey()=337 Then
xpos-3→xpos
PxlCrcl ypos,xpos,5,1
EndIf

If getKey()=257 Then
Goto end 
EndIf

EndLoop
Lbl end

EndPrgm

This creates an endless game loop that checks if the left, right, or delete buttons are being pressed and draw a circle left or right accordingly or end the program entirely. However, this method seems to run extremely slowly and I have seen much smoother movement in other demonstrations. Is there something wrong with my method and if so how can I improve it?

Liebman answered 16/4, 2015 at 19:35 Comment(1)
Have you tried setting getKey() to a variable then testing the variable? I don't have my calculator on me to test this, but it seems like maybe running getKey() multiple times (one for every If statement) might slow it down more than simply testing a variable.Gormless
L
3

Sorry, I use a TI-84, but this method should still work.

The getKey() function is the function that is creating a delay. You only have to run the getKey() function once if you put the output into a variable. In TI-84, you can just do

getKey->K

You should be able to do exactly the same thing with TI-89.

Hope this helps!

Ld answered 16/12, 2015 at 16:52 Comment(0)
S
0

What I usually do is use a While not() statement then check the answer afterwards.

For example

loop
0 -> X
while not(X)
    do something every iteration
    getKey()
    if Ans: Ans -> X
Check values of X with If statements
End loop

In this way you are just executing some code (Maybe some basic addition and subtraction or a For loop to slow things down) and a single If statement on each loop of the While statement instead of checking a lot of If statements on each loop.

This serves you well and allows you to do something on each iteration of the While loop while still checking for a keypress.

Note that I usually program on TI-84s, but the idea should work much the same in the TI-89 with a bit of tweaking.

Stoicism answered 24/6, 2015 at 21:49 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.