
-----------------------------------
Paul
Sun Mar 14, 2004 10:39 am

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:

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:

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 :(

-----------------------------------
recneps
Sun Mar 14, 2004 10:45 am


-----------------------------------
KeyDown uses "char"s they're declared like this
var letter:char:=chr(numberofcharhere)
from there, just go to turing reference to find the codes. Eg.
var up:char:=chr(200) is the code for a variable to represent up arrow. Got it? ;)

-----------------------------------
Paul
Sun Mar 14, 2004 10:49 am


-----------------------------------
oh, so I'd have something like this:

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
Sun Mar 14, 2004 12:24 pm


-----------------------------------
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.
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
Sun Mar 14, 2004 12:28 pm


-----------------------------------
Don't have to understand it, it works now :P

-----------------------------------
Cervantes
Sun Mar 14, 2004 12:29 pm


-----------------------------------
hey paul.  You don't need the part with letters and CL in there any more.

it works like this:
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
Sun Mar 14, 2004 12:34 pm


-----------------------------------
I know, but CL changes, just look at my finished program in the source code section, its not that well coded but meh.

-----------------------------------
recneps
Sun Mar 14, 2004 12:38 pm


-----------------------------------
Well at least you got it working :) Thats what matters.
