
-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 1:51 pm

checking arrows
-----------------------------------
aite got the attacks,, i got a quick question is there a way to check what key has been pressed last for example if i press the left arrow to move to knwo that and then to display the attack on the left side instead of the normal side?

-----------------------------------
Tony
Sat Jun 19, 2004 1:57 pm


-----------------------------------
you keep a buffer, where you record the keys (or key if you just need one) pressed. So if you want to look up the history of input, you just check the buffer string

-----------------------------------
eNc
Sat Jun 19, 2004 2:30 pm


-----------------------------------
you keep a buffer, where you record the keys (or key if you just need one) pressed. So if you want to look up the history of input, you just check the buffer string


whats a buffer ? is it like an array or somthing ?

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 3:08 pm


-----------------------------------
ya what is a buffer i never learned this in class lol

-----------------------------------
SuperGenius
Sat Jun 19, 2004 3:09 pm


-----------------------------------
have a string var an everytime there is a keypress do this:


if keypress then %there has been a keystroke
input:=input + keystroke
end if


everytime someone presses a key it is added to one long string var. Also you could make an elsif substructure to check if they press delete and tell the program to subtract the last character from your input string.

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 3:47 pm


-----------------------------------
ok so for example now i want a picture display i can go liek


if keypress then %there has been a keystroke 
input:=input + keystroke 
end if 

if input = (KEY_RIGHT_ARROW) THEN
Pic.Draw (back,0,0,picCopy0
end if

something like that or do i instead of if input i put if keystroke? :oops:
and do i put this in my input.keydown loop

-----------------------------------
SuperGenius
Sat Jun 19, 2004 6:07 pm


-----------------------------------
if what you're trying to do is display a certain picture when the right arrow is pressed, you're off a bit, and I may have confused you earlier. If you want to display a picture at the exact time that the right arrow is pressed then you would do someting like option one. but to check if there has been a right key press in the past you would need to do something like option 2, and put the checking part at the end of my example where you want to check for a right arrow press. 

% use this to find ord codes for keys
% var a : string (1)
% loop
%     getch (a)
%     put ord (a)
% end loop
%
%
% %option 1
% var chars : array char of boolean
% loop
%     Input.KeyDown (chars)
%     if chars (KEY_RIGHT_ARROW) then
%         put "your code for a right arrow press here"
%         delay (100)
%     end if
% end loop

%option 2
var keystroke : string (1)
var input : string := ""
loop
    getch (keystroke)
    exit when ord (keystroke) = 207 %press end to exit
    if ord (keystroke) not= 8 then % 8 is the ord number of backspace key
        input := input + intstr (ord (keystroke)) + " "
    else
        if length (input) > 0 then
            input := input (1 .. * -1) %delets the last char if you pressed backspace
        end if
    end if
end loop
put input

%checker thing

if index (input, "205") not= 0 then
    put "they pressed the right arrow"
else
    put "they didnt press the right arrow"
end if


you can see all of the ord numbers that they pressed after you exit the loop.

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 7:17 pm


-----------------------------------
ahem aite, yah i'm trying to display a certain picture when the character is facing right and certian picture when chracter is facing left and the only way i though of is to check what arrow has been pressed beofre the picture is dispalyed.. so ill give that thing a try and see if it works.

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 7:32 pm


-----------------------------------
hum yah it works ehe but it kidna gets stuck so when ever i press the rigth arrow it keeys applying that picture hum here i attached a file so u can see what i'm trying to do might explain a thing or two better  :roll:

-----------------------------------
Tony
Sat Jun 19, 2004 7:43 pm


-----------------------------------
can't you just have a variable for character's direction ?

whenever an arrow key is pressed, that direction is set to the new value. Then whenever you need to reference the direction that character is facing (such as to pick which picture to draw) you just take the value from that variable

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 8:35 pm


-----------------------------------
hum, u eman liek a counter px :=px? or what lol and then if it is less then it was before put another pic ahem i guess i could try it :p

-----------------------------------
TrAnCeIn4LiFe
Sat Jun 19, 2004 8:46 pm


-----------------------------------
ah woot got it working thx bro  :lol:
