Computer Science Canada Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
Author: | Shadow456732 [ Tue Dec 18, 2012 7:48 pm ] | ||
Post subject: | Input.KeyDown Problems... Seems to keep the value of the key until something happens... | ||
What is it you are trying to achieve? This program is essentially like one of those asteroid dodge programs. You are the ball, avoid all in coming objects. Though, the problem is, that when you lose, the game ends. I want to make it so clicking enter will bring you back to the main menu. And then you click enter once more to start the game. What is the problem you are having? When i click enter in the end to restart the loop, it seems to start where the game starts... So it dosen't show the intructions, and it dosen't wait for the input. Describe what you have tried to solve this problem Tried putting delay's in a few places to see wether or not it actually did go through that code. It seemed to, but it would assume that enter was clicked when it wasn't. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using The second newest. As the newest has a bug with making stand alone programs lol. Thanks for any help ![]() |
Author: | TerranceN [ Tue Dec 18, 2012 9:20 pm ] | ||||
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... | ||||
Since you have inner loops that wait for you to press enter at the beginning and the end of the outer loop, you essentially have a situation like this:
If you run that, you will find that the program runs so fast that after pressing enter to get out of the 'you lose' loop, it goes through the instructions loop before you can take your finger off enter. One way to fix this problem is to keep track of the keys that were down the previous iteration of the loop, then only exit when enter is down but wasn't before (i.e. right when it is pressed). This gives the desired behaviour of having to press enter twice to get through both loops:
|
Author: | Shadow456732 [ Tue Dec 18, 2012 9:33 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
Hmm, sounds good, though could i just change the value of key before the check? I'll try that out as well thanks ![]() EDIT: Also, is there a way to "clear" the value of Input.KeyDown?? |
Author: | Shadow456732 [ Tue Dec 18, 2012 9:40 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
Alright! After trying it out, it seems to work. Though for future reference, what does the "~" do in this situation? |
Author: | TerranceN [ Tue Dec 18, 2012 9:43 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
The problem with changing the value of key is you need to continuously keep updating key using Input.KeyDown to determine when enter is pressed. So even if you change the value of key, the next Input.KeyDown will overwrite your change. '~' is just shorthand for 'not'. |
Author: | Shadow456732 [ Tue Dec 18, 2012 9:47 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
Makes sense. Thanks a bunch , works like a charm now! ![]() |
Author: | Shadow456732 [ Tue Dec 18, 2012 9:50 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
Lol, sorry, final thing. I found out that if you do "and not= prekey(KEY_ENTER) then" instead of "and ~prekey(KEY_ENTER) then" dosen't seem to work.... Also, putting the not= in between prekey and (KEY_ENTER), it dosen't work either. How would i do it other than with a ~ if possible haha |
Author: | TerranceN [ Tue Dec 18, 2012 10:00 pm ] |
Post subject: | RE:Input.KeyDown Problems... Seems to keep the value of the key until something happens... |
'~' is a shorthand for the negation operator 'not' (i.e. 'not false' is 'true'), not 'not='. If you do "and not prekey(KEY_ENTER) then" it should work. |