Get technical support about the C++ source code and about
Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
-
TheMatrix - Posts:20
- Joined:2004-10-19, 10:06
Key Inputs
Post
by TheMatrix » 2004-10-19, 22:25
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

-
Shadow
- Posts:195
- Joined:2004-08-28, 06:00
- Location:Minesota, USofA
-
Contact:
Post
by Shadow » 2004-10-20, 03:27
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
-
TheMatrix - Posts:20
- Joined:2004-10-19, 10:06
Post
by TheMatrix » 2004-10-20, 09:26
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
-
Camille - Posts:11
- Joined:2004-08-25, 10:03
Post
by Camille » 2004-10-20, 09:52
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.
-
TheMatrix - Posts:20
- Joined:2004-10-19, 10:06
Post
by TheMatrix » 2004-10-20, 09:52
I got it
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:
-
Shadow
- Posts:195
- Joined:2004-08-28, 06:00
- Location:Minesota, USofA
-
Contact:
Post
by Shadow » 2004-10-20, 13:38
cool. good to know you figured it out now. now i wish i could be arsed to learn some...
Users browsing this forum: No registered users and 2 guests