I'm having a little problem with my getKey loop in my Chess game. It's fast, but unreliable. Right now, I'm using a While to see which key is pressed. If an arrow key is pressed, it moves the pixel. Is there a method of selection that I can use without the help of programs not made by me? Because the pixel sometimes doesn't move when I press the arrow..... When it DOES move the pixel, though, it moves it almost instantaneously.
Please upload your program via http://sc.cemetech.net and post the code from that using one of the options below the code, at the bottom of the code box. I believe you want the one labeled phpbb.
I am sure between all of us programmers here, we can come up with at least 5 ways to get you what you want.
I am sure between all of us programmers here, we can come up with at least 5 ways to get you what you want.
I'm sure you can find a LOT of things wrong with my code.
Here's my whole program so far. (It does NOT support DCS, but I will make it support it later, when DCS is complete)
Code:
The reason why it looks a little different is because it was garbage in the "Post a Reply" window.
Here's my whole program so far. (It does NOT support DCS, but I will make it support it later, when DCS is complete)
Code:
::"2-player chess.
:ClrHome
:ClrDraw
:Func
:CoordOn
:GridOff
:AxesOff
:LabelOff
:ExprOn
:FnOff
:0->Xmin
:94->Xmax
:0->Ymin
:62->YMax
:1->XScl
:1->YScl
:1->Xres
:Input "P1?",Str1
:While length(Str1)>7
:Disp "<= 7 chars.
:Input "P1?",Str1
:End
:Input "P2?",Str2
:While length(Str2)>7
:Disp "<= 7 chars.
:Input "P2?",Str2
:End
:RecallPic 0
:Text(3,65,Str1
:Text(50,65,Str2
:8,8->dim([A]
:4,1,0,0,0,0,1,4->lROOK
:3,1,0,0,0,0,1,3->lKNIG
:2,1,0,0,0,0,1,2->lBISH
:5,1,0,0,0,0,1,5->lQUEE
:6,1,0,0,0,0,1,6->lKING
:List->Matr(lROOK,lKNIG,lBISH,lQUEE,lKING,lBISH,lKNIG,lROOK,[A]
:[A]->[B]
:1->W
:9->R
:1->C
:While W=1
:If getKey=26 and C<62
:Then
:Pt-Off(C,R
:C+7.75->C
:Pt-Change(C,R
:End
:If getKey=25 and R<62
:Then
:Pt-Off(C,R
:R+7.75->R
:Pt-Change(C,R
:End
:If getKey=24 and C>0
:Then
:Pt-Off(C,R
:C-7.75->C
:Pt-Change(C,R
:End
:If getKey=34 and R>0
:Then
:Pt-Off(C,R
:R-7.75->R
:Pt-Change(C,R
:End
:End
The reason why it looks a little different is because it was garbage in the "Post a Reply" window.
what I might do is something like
Code:
Code:
While W=1
0->K (or del K)
Repeat K
getkey -> K
end
rest of code
end
Thanks, that fixed it. I guess the program was going through every possibility of getKey and if it hit one of them that I told it to do, THEN it would move the pixel.
(Sorry for going overboard, but I have nothing to do so i am trying to occupy myself )
You do not even need the 0->K, getkey would store a 0 to K anyways if nothing was pressed.
Here is my method of getkeys
Code:
It is really a matter of preference, but mine is smaller (and i think smaller, doesn't storing to variables take longer than storing to ans? Plus it still stores to ans anyways.)
I tested it, each (just the getkey part, no while w=1 stuff) in a program named TEST (13 bytes with nothing in it, also I used del var for rivereye's). Rivereye's is 25, so 12 bytes. Mine is 23, so 10 bytes. Really this is only if you REALLY want to save a few bytes.
Oh yeah, if you are wondering why this code didn't work
Code:
It is because (atleast from my experience it is) everytime you use the getkey command, it resets it to 0. So you would have to be lucky and press the corrosponding arrow right before the getkey for that code to work.
rivereye wrote:
what I might do is something like
Code:
Code:
While W=1
0->K (or del K)
Repeat K
getkey -> K
end
rest of code
end
You do not even need the 0->K, getkey would store a 0 to K anyways if nothing was pressed.
Here is my method of getkeys
Code:
:Repeat Ans
:getkey
:end
:Ans->K
It is really a matter of preference, but mine is smaller (and i think smaller, doesn't storing to variables take longer than storing to ans? Plus it still stores to ans anyways.)
I tested it, each (just the getkey part, no while w=1 stuff) in a program named TEST (13 bytes with nothing in it, also I used del var for rivereye's). Rivereye's is 25, so 12 bytes. Mine is 23, so 10 bytes. Really this is only if you REALLY want to save a few bytes.
Oh yeah, if you are wondering why this code didn't work
Code:
:While W=1
:If getKey=26 and C<62
:Then
:Pt-Off(C,R
:C+7.75->C
:Pt-Change(C,R
:End
:If getKey=25 and R<62
:Then
:Pt-Off(C,R
:R+7.75->R
:Pt-Change(C,R
:End
:If getKey=24 and C>0
:Then
:Pt-Off(C,R
:C-7.75->C
:Pt-Change(C,R
:End
:If getKey=34 and R>0
:Then
:Pt-Off(C,R
:R-7.75->R
:Pt-Change(C,R
:End
It is because (atleast from my experience it is) everytime you use the getkey command, it resets it to 0. So you would have to be lucky and press the corrosponding arrow right before the getkey for that code to work.
actually, if you don't have the 0->k, it won't enter the loop if you press a wrong key. Just as a heads up.
rivereye wrote:
actually, if you don't have the 0->k, it won't enter the loop if you press a wrong key. Just as a heads up.
It won't? what do you mean 'wrong key'? I have had it that if you press enter a lot, sometimes it will pause until u press it again.
-
Harq
- Calculator Deity (Posts: 1857)
- 12 Jul 2006 05:30:10 pm
- Last edited by Harq on 12 Jul 2006 05:33:58 pm; edited 1 time in total
rivereye wrote:
well, if you say, press a key he does not have a thing programmed for, that is wrong key.
but then it would loop back...
ok, let me look at my code really quickly, it may have been slightly different I used in the program
yeah, this way does not require the 0->K line in my code, my bad.
yeah, this way does not require the 0->K line in my code, my bad.
It all depends on whehter getKey modifies K if nothing is pressed. I'm not sure what it does exactly, but I would suspect that it would store 0 which makes me believe Harq is correct. Remember, Repeat checks the condition at the end of the loop.
Chipmaster wrote:
It all depends on whehter getKey modifies K if nothing is pressed. I'm not sure what it does exactly, but I would suspect that it would store 0 which makes me believe Harq is correct. Remember, Repeat checks the condition at the end of the loop.
in my set up it doesn't do anything until u press a key, then it stores it to K. Then it goes through a series of loops and normally i have it inside a loop that if K= (some number) it exits.
chip, you are right, it goes through once on a Repeat, then checks, While checks before going in though.
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
» Go to Registration page
» Goto page 1, 2, 3 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 1 of 3
» 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
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