But how to work with getButtons in script?
I need to do this: when key is pressed then some script function is running.
Now I try to realize it with level script, start thread func from main () & check into thred func some buttons via getButtons. But when I try to do this in while (1) it's causing an loop error.
How to listen key events?
Thanks.
Like i said before normal key usage in idtech 4 script is very limited, there's only a few keys available and there's no way in vanilla idtech 4 to get impulses by script (i changed all that for my version of fhdoom engine tho).
But here is how (before i was coding on the engine c++) i managed key/buttons events for scripts.
//Custom help function made by me to manage buttons - this was on a separate script file.
float giveButtons(float userbuttons, string buttonType)
{
float result;
/*
btn0 = 1 & userbuttons; // Attack
btn1 = 2 & userbuttons; // Run
btn2 = 4 & userbuttons; // Zoom
btn3 = 8 & userbuttons; // Scores only for MP
btn4 = 16 & userbuttons; // Mouse look
btn5 = 32 & userbuttons; // Button 5
btn6 = 64 & userbuttons; // Button 6
btn7 = 128 & userbuttons; // Button 7
*/
if (buttonType == "btn0")
{
result = 1 & userbuttons;
}
else if (buttonType == "btn1")
{
result = 2 & userbuttons;
}
else if (buttonType == "btn2")
{
result = 4 & userbuttons;
}
else if (buttonType == "btn3")
{
result = 8 & userbuttons;
}
else if (buttonType == "btn4")
{
result = 16 & userbuttons;
}
else if (buttonType == "btn5")
{
result = 32 & userbuttons;
}
else if (buttonType == "btn6")
{
result = 64 & userbuttons;
}
else if (buttonType == "btn7")
{
result = 128 & userbuttons;
}
return result;
}
// Code i used on the player script
#define USE_BTN giveButtons(buttons, "btn0")
float buttons;
buttons = $player1.getButtons();
if ( USE_BTN ){
entity.callFunction("someFunctionName");
}
That code above was inspired by the following documentation on
modWiki.
If you want a specific key then bind that key to the command you want to run. It can run any console command, including script functions.
IE
bind h "trigger scriptfunction"
Pretty sure "trigger" will activate a script function.
Hum i didn't knew about that! If it indeed work then it indicates that by using that trick you can use more than the 7 buttons (three really some are hardcoded in the c++ code) that the player getbuttons() func provides.

But now that i think about it, how does this trick knows what function in what script file i'm talking about? I assume i have to include the full path to the script file not only the function name? Because if i only need to include the name then that tells me that function needs to be uniquely named and that imo is a serious limitation, i'm wrong?