Page 1 of 1

Key Inputs

Posted: 2004-10-19, 22:25
by TheMatrix
I've got a problem with the Key Inputs

I will do a Function in Think() when I press a key. But a if-clause with the PlayerCommand.Keys as arguement doesnt work, because the Function will be call very much times. Does anybody know, how could do that the function is called only 1 time when the key is pressed

Sry for my Englisch , I'm German :wink:

Posted: 2004-10-20, 03:27
by Shadow
u need to have a var that is set when the key is pushed and unset when its released. then inside the func check if that var is set or not. or if u have something that has different calls like keypress,keydown,keyup you can use those

Posted: 2004-10-20, 08:47
by TheMatrix
Thank you, thats a very good idea :)

Posted: 2004-10-20, 09:26
by TheMatrix
I made a private Variable bool Enable_Key_Walk and put this code in Think()
if ((Keys & PCK_Walk) && (Enable_Key_Walk))
{
if (Class == Class_Medic)
{
Enable_Key_Walk = 0;
EngineFunctions->PrintDebug("Code")
...

Code: Select all

 ...
            }
      }

if (((Keys & PCK_Walk) == 0) && (Enable_Key_Walk == 0)) 
     {
        EngineFunctions->PrintDebug("Switch")
        Enable_Key_Walk = 1;
      }
[/quote]
But the [Code] and "Switch" is still called 2 times. I dont understand this :?: 

PS: The Code Display dont work, and by Quote Display there is no formation, sry

Posted: 2004-10-20, 09:52
by Camille
ok i understand, it may not be your code but because of the think function :

think is called two time :
- 1 by the server side
- 1 by the client side

so if you test as me in only one computer then the two call occure...

perhaps you could use a variable named "think_on_serverside" (or something like that) to add a test.

Posted: 2004-10-20, 09:52
by TheMatrix
I got it :D

The code is called twice because it is called on Client and on Server Side
So you have to add ThinkingOnServerSide as arguement in the if clauses and it works
if ((Keys & PCK_Walk) && (Enable_Key_Walk) && (ThinkingOnServerSide))
{
if (Class == Class_Medic)
{
Enable_Key_Walk = 0;
EngineFunctions->PrintDebug("Code")
...

Code: Select all

 ... 
} 
} 

if (((Keys & PCK_Walk) == 0) && (Enable_Key_Walk == 0) && (ThinkingOnServerSide)) 
{ 
EngineFunctions->PrintDebug("Switch") 
Enable_Key_Walk = 1; 
} 
[/quote]

Edit: Hmm, you were faster :wink:

Posted: 2004-10-20, 13:38
by Shadow
cool. good to know you figured it out now. now i wish i could be arsed to learn some...