Input.KeyDown problem
Author |
Message |
Paul
|
Posted: Sun Mar 14, 2004 10:39 am Post subject: Input.KeyDown problem |
|
|
Im trying to get the program to detect if a predetermined letter has been pressed. and the predetermined letter is going to be a variable. I don't have alot of experience with this so I dunno if this is the way to do it. And I got an error.
in short this is it:
code: |
var word, letter: string:=("horse")
var CL: int:=1
var chars : array char of boolean
letter:=word(CL)
loop
Input.KeyDown (chars)
if chars (letter) then
exit
end if
end loop
|
In here, Im trying to check if the user has typed the frist letter of horse, which is h, and if h has been pressed, it exits the loop. Since this is during another part of the program, Im not using getch.
but I recieve an error on the line:
code: |
if chars (letter) then
|
of array subscript is out of range
I looked at the reference, and I thought if chars('t') works why shouldn't letter, which is a string with the length of one work?
Im baffeled, since if I use chars('h') it works, and if I use chars(letter) it won't, even though letter = h. Im putting a halt on what Im doing currently cause of this |
|
|
|
|
|
Sponsor Sponsor
|
|
|
recneps
|
Posted: Sun Mar 14, 2004 10:45 am Post subject: (No subject) |
|
|
KeyDown uses "char"s they're declared like this
code: | var letter:char:=chr(numberofcharhere) |
from there, just go to turing reference to find the codes. Eg.
code: | var up:char:=chr(200) | is the code for a variable to represent up arrow. Got it? |
|
|
|
|
|
Paul
|
Posted: Sun Mar 14, 2004 10:49 am Post subject: (No subject) |
|
|
oh, so I'd have something like this:
code: |
var word, letter: string:=("horse")
var CL: int:=1
var chars : array char of boolean
letter:=word(CL)
var let:char:=chr(ord(letter))
loop
Input.KeyDown (chars)
if chars (let) then
exit
end if
end loop
|
it works, so, the chars (thingy)
thingy has to be a char? |
|
|
|
|
|
recneps
|
Posted: Sun Mar 14, 2004 12:24 pm Post subject: (No subject) |
|
|
noooooo look in turing reference, theres a thing on front page that says "keycode values returned by...." clikc that and it give you the number for each key....
ex.
code: | var a:char:=chr(97)
var A:char:=chr(65)
var chars:array char of boolean
loop
Input.KeyDown (chars)
if chars(a) then
put "You pressed key # 97, otherwise known as 'a'"
elsif chars(A) then
put "You pressed key #65, otherwise known as 'A'"
end if
end loop |
Understand it a tad more? |
|
|
|
|
|
Paul
|
Posted: Sun Mar 14, 2004 12:28 pm Post subject: (No subject) |
|
|
Don't have to understand it, it works now |
|
|
|
|
|
Cervantes
|
Posted: Sun Mar 14, 2004 12:29 pm Post subject: (No subject) |
|
|
hey paul. You don't need the part with letters and CL in there any more.
it works like this:
code: | var word : string := ("horse")
var chars : array char of boolean
var let : char := chr (ord (word (1)))
loop
Input.KeyDown (chars)
if chars (let) then
exit
end if
end loop
|
|
|
|
|
|
|
Paul
|
Posted: Sun Mar 14, 2004 12:34 pm Post subject: (No subject) |
|
|
I know, but CL changes, just look at my finished program in the source code section, its not that well coded but meh. |
|
|
|
|
|
recneps
|
Posted: Sun Mar 14, 2004 12:38 pm Post subject: (No subject) |
|
|
Well at least you got it working Thats what matters. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|