Jump to content

Key Detection Problems


Recommended Posts

Hi, i hate posting so soon after my other thread but i just can not get Game.IsKeyDown() to work. I have it detect if the key is pressed (Y) while a bool is active which is only active while a timer is on. I have tried with just the IsKeyDown method but it still will not work. I have tried in a normal process, in a while loop and in a new Game Fiber. Could anyone see if i'm doing anything wrong? 

Here's a pic of the relevant code (I have highlighted the area with game.iskeydown) : http://s30.postimg.org/k4x1ii6o1/jpg.png

I had to upload it as LCPDFR.com would not allow me to upload pictures, and neither would imgur :pinch:

 

 

Edit: Do you think it has anything to do with this? It seems to be looping throught the 'Key Not pressed' code more and more every time it's run http://s21.postimg.org/g3ubu2tyf/adding.jpg

 

Edited by AnIdioticMonkey
Link to comment
Share on other sites

41 minutes ago, LtFlash said:

Try to insert "break;" after "toAcceptTimer.Enabled = false;" It will stop the while(true) loop so the control will return where it should be.

Unfortunately that does not work, it still waits before the timer elapses before displaying we haven't pressed the key but the Game.iskeydown never returns true

 

Edit: Do you think it has anything to do with this? It seems to be looping throught the 'Key Not pressed' code more and more every time it's run http://s21.postimg.org/g3ubu2tyf/adding.jpg

Edited by AnIdioticMonkey
Link to comment
Share on other sites

Definitely, it should not happen but I don't see a reason why it is so. You can put the while(true) into new fiber like that:

GameFiber.StartNew(delegate
            {
                while (true)
                {
                     //
                    GameFiber.Yield();
                }
            }
            );

and see what happens.

Link to comment
Share on other sites

53 minutes ago, LtFlash said:

Definitely, it should not happen but I don't see a reason why it is so. You can put the while(true) into new fiber like that:

GameFiber.StartNew(delegate
            {
                while (true)
                {
                     //
                    GameFiber.Yield();
                }
            }
            );

and see what happens.

Have an internet high five! You fixed it and it now works perfectly, thank you! I'm sure i have already tried the gamefiber approach but maybe it failed because i didn't have the break; ? Anyway, thank's for all your help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...