Author |
Message |
JakeTakeLake
|
Posted: Mon Feb 25, 2013 7:03 pm Post subject: How to make KeyDown provide one output? |
|
|
What is it you are trying to achieve?
In my game, I have a character controlled by keys. What I'm trying to do is make the KeyDown provide a single output, until it is released and pressed again. As opposed to providing multiple outputs for the duration that the key is pressed. Sorry if I didn't explain well.
For example, I want the sprite to be changed to "punch" for one frame when the key 'd' is pressed. Instead, the sprite is being changed to "punch" for the time that the key is held down(multiple frames).
What is the problem you are having?
Implementing this.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
%for example
loop
if chars ('d') then
Sprite.ChangePic (player1,punch )
end if
end loop
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dreadnought
|
Posted: Mon Feb 25, 2013 7:33 pm Post subject: Re: How to make KeyDown provide one output? |
|
|
Basically you want to check if the key was down the last time you called Input.KeyDown. How might you be able to keep track of the last state of the key? |
|
|
|
|
|
evildaddy911
|
Posted: Tue Feb 26, 2013 11:24 am Post subject: Re: How to make KeyDown provide one output? |
|
|
what you need is 2 keys variables:
- 2 variables: "current", "last"
- initialize "last"
- start loop
- update "current"
- check current(K)=true, last(K) = false
- "last"="current"
- end loop |
|
|
|
|
|
JakeTakeLake
|
Posted: Tue Feb 26, 2013 6:24 pm Post subject: RE:How to make KeyDown provide one output? |
|
|
here's what i did, but it doesn't work
Turing: |
var keydown: int := 1
loop
if chars ('d') and keydown= 1 then
Sprite.ChangePic (player1,punch )
keydown= 0
end if
if not chars ('d') then
keydown= 1
end if
end loop
|
|
|
|
|
|
|
Tony
|
Posted: Tue Feb 26, 2013 7:37 pm Post subject: RE:How to make KeyDown provide one output? |
|
|
try adding
code: |
put "The value of chars(d) is: ", chars('d')
|
before every place where you are reading it. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
evildaddy911
|
Posted: Wed Feb 27, 2013 8:40 am Post subject: RE:How to make KeyDown provide one output? |
|
|
what i meant by "update 'current'" is by using Input.KeyDown().
also, what didn't work? did it crash or give the wrong output?
if it crashed, why? (check the bottom of the window for error messages) |
|
|
|
|
|
|