Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to make KeyDown provide one output?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JakeTakeLake




PostPosted: 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
Sponsor
sponsor
Dreadnought




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
evildaddy911




PostPosted: 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)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: