I meant this:


Code:
:1→A
:1→B
:Output(1,1,"X
:While 1

:0:Repeat Ans
:getKey
:End

:While Ans
:Ans→K
:Output(A,B,"_
:A-(K=25 and A-1)+(K=34 and A-8→A
:B-(K=24 and B-1)+(K=26 and B-16→B
:Output(A,B,"X
:getKey
:End

:End

You might not notice a huge difference with something so simple, but if you have other actions for other keys, it makes an improvement. (You would replace "While Ans" with "While Ans=34 or 2>abs(Ans-25")
elfprince13 wrote:
Deep Thought wrote:


Code:
:1→A
:1→B
:Output(1,1,"X
:While 1
:Repeat K
:getKey→K
:End
:While K
:Output(A,B,"_
:A-(K=25 and A-1)+(K=34 and A-8→A
:B-(K=24 and B-1)+(K=26 and B-16→B
:Output(A,B,"X
:End
:End


Never thought of that. I'll try it.

EDIT: WOW THAT IS FAST. How did I never learn that?


Shouldn't it be this? It doesn't look like there is any way that K would become 0 in that second inner loop.


Code:
:1→A
:1→B
:Output(1,1,"X
:While 1
:Repeat K
:getKey→K
:End
:Output(A,B,"_
:A-(K=25 and A-1)+(K=34 and A-8→A
:B-(K=24 and B-1)+(K=26 and B-16→B
:Output(A,B,"X
:End


No, actually I left out a getKey→K in the second loop, as in:


Code:
:1→A
:1→B
:Output(1,1,"X
:While 1
:Repeat K
:getKey→K
:End
:While K
:Output(A,B,"_
:A-(K=25 and A-1)+(K=34 and A-8→A
:B-(K=24 and B-1)+(K=26 and B-16→B
:Output(A,B,"X
:getKey→K
:End
:End


EDIT: Really? So the speed would be worth the extra memory if I used Ans for the getKey, then stored it to K? Either way, that is a lot faster than what I've been using. Thanks for the tip.
You probably want a DelVar K in there somewhere.
Deep Thought wrote:
EDIT: Really? So the speed would be worth the extra memory if I used Ans for the getKey, then stored it to K? Either way, that is a lot faster than what I've been using. Thanks for the tip.
This is what came to me as a surprise as well.


EDIT@elfprince13 Maybe in place of the second getKey->K?
Deep Thought wrote:
So the speed would be worth the extra memory if I used Ans for the getKey, then stored it to K?


"Worth" is pretty subjective, but I would say that if you have a lot of different types of responses to keypresses (such as in some games), the speed is worth it. Do remember that if your action is not repetitive (as in, the user isn't expected to press the same type of key repeatedly for some time), doing this will actually slow down response time.

A good place to use multiple loops like that is in text editing, because when people type, there is very little time in between keypresses. In addition, when deleting/moving cursors, people tend to hold down keys.... so here is a string editor, for situations in which the user wants to edit an existing string, or if you want the UI to be completely graphscreen based.


Code:
:":-->Str0
:" -->Str1
:ClrHome
:While 1
:Output(1,1,Str0+"<"+Str1
:0:Repeat Ans
:getKey
:End

//adds characters as the user types
:While Ans>40
:Str0+sub(ABC  DEFGHIJKLMNOPQRSTUVWXYZθ   .?  ", Ans-5iPart(.1Ans+4),1-->Str0
:Output(1,1,Str0+"<"+Str1
:getKey
:End

:/deletes characters as the user presses delete
:While Ans=23 and Str0!=':
:sub(Str0,1,length(Str0)-1-->Str0
:Output(1,1,Str0+"<"+Str1
:getKey
:End

//Checks to see if the user is trying to move the cursor left/right
:If 2>abs(Ans-25
:Then

//moves the cursor left
:While Ans=24 and Str0!=":
:length(Str0-->L
:sub(Str0,L,1)+Str1-->Str1
:sub(Str0,1, L-1-->Str0
:Output(1,1,Str0+"<"+Str1
:getKey
:End

//moves the cursor right
:While Ans=26 and Str1!="
:length(Str1-->L
:Str0+sub(Str1,1,1-->Str0
:sub(Str1,2, L-1-->Str1
:Output(1,1,Str0+"<"+Str1
:getKey
:End

:End

:End


Btw, whenever I use "!=", I mean "not equal to"
I have another question on a related topic:

This may seem strange, but remember how whenever you hold down a repeating key, it registers once, then pauses for about half a second, then starts repeating quickly? For example, in that simple movement program above, if you pressed the right arrow, the X would move right once, pause for a moment, then zoom toward the end. Well, when playing one of my games on any SE calculator, that little pause occasionally results in the program moving forward before the next keypress is registered. This is especially annoying when I'm trying to move from one platform to another, and my character falls an extra space because the calculator didn't have time to register the right arrow in time.

Is there any way to avoid that? I know there are assembly programs that reduce the amount of time between the first and second keypress registers, but I wanted to keep this program pure BASIC. Is there a way to fix this?[/url]
[Moved To New Topic]
Deep Thought wrote:
This may seem strange, but remember how whenever you hold down a repeating key, it registers once, then pauses for about half a second, then starts repeating quickly?


I don't exactly know why it does this, but the same happens to me. Alike how in MirageOS, the first getKey is not recognized, you need to code in a backup in case the key isn't captured.

For example, instead of just "getKey", try


Code:
:DelVar C
:Repeat Ans or C>5
:C+1-->C
:getKey
:End


It's annoying, and takes up space, but it does make moving around smoother.

Btw, you can use Celtic3 to check if you're on a 84 or an 83, and adjust the limit on C (counter) accordingly.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement