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?

  • 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. – jaysoncopes May 18 '15 at 14:04

2 Answers2

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!

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.

Zenohm
  • 548
  • 6
  • 17