News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

getButtons

Started by Bladeghost, February 03, 2015, 08:54:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bladeghost

Question? is the  scripting limited to getButtons 32,64 and 128?
and only just 3 or am I overlooking something.
in the AI_Player.script to assigning button assignments or can other numbers be used.
currently in my project these three are in use and I need one more.
anybody know? Thanks.

Radegast

These buttons are available in the BFG edition:

Code (cpp) Select
// usercmd_t->button bits
const int BUTTON_ATTACK = BIT( 0 ); // <-- 1
const int BUTTON_RUN = BIT( 1 ); // <-- 2
const int BUTTON_ZOOM = BIT( 2 ); // <-- 4
const int BUTTON_SCORES = BIT( 3 ); // <-- 8
const int BUTTON_USE = BIT( 4 ); // <-- 16
const int BUTTON_JUMP = BIT( 5 ); // <-- 32
const int BUTTON_CROUCH = BIT( 6 ); // <-- 64
const int BUTTON_CHATTING = BIT( 7 ); // <-- 128

argoon

old thread i know, but i nice place to put info about this function...


From what the link below say, in script we are limited to those buttons posted above, for c++ beside buttons we also have access to the impulse functionality.

Impulses run only one time per key press.

Buttons run for the time you keep pressing the key, even if you press&release quickly it will run the code more than one time, something very frustrating when you want a action to happen one time per key press and unfortunately for now i don't know if we really have access to impulses trough script, so for the time being i need script hacks to prevent the sticky key functionality, not pretty...

From the link below it seams even in c++ we can't use some of the buttons to do other functions then the ones coded in the engine (unless you change that system of course).

http://web.archive.org/web/20050404051342/http://www.planetdoom.com/d3cc/tut02.html

motorsep

Doom 3 modding is dead, wake up! We are in 2017 and Quake still gets more mods and activity than Doom 3.

MrC

Quote from: motorsep on March 24, 2017, 09:45:23 AM
Doom 3 modding is dead, wake up! We are in 2017 and Quake still gets more mods and activity than Doom 3.

Why are you here?

motorsep


argoon

Quote from: MrC on March 24, 2017, 03:35:03 PM
Quote from: motorsep on March 24, 2017, 09:45:23 AM
Doom 3 modding is dead, wake up! We are in 2017 and Quake still gets more mods and activity than Doom 3.

Why are you here?

On the lack of administrator action, the best thing to do to a guy like that is to ignore it.

bitterman

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.

The Happy Friar

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.

argoon

#9
Quote from: bitterman on August 26, 2017, 12:22:23 PM
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.


Quote from: The Happy Friar on August 26, 2017, 02:04:34 PM
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?

bitterman

#10
QuotePretty sure "trigger" will activate a script function.

Looks like it's must be an entity on the map with "call" key/val.

And looks like in thread func while(1) must be used with waitFrame() at the end of cycle.

Yes, that's works:

void main() {thread isPressed()}

void isPressed() {

while(1) {

(some check via argoon's modwiki link)

sys.waitFrame() // error without it

}
}

argoon

You should always include a sys.waitframe() or sys.wait(somenumber) in all loops or they will cause a loop error, btw there's a helper function included in Doom 3 called:


eachFrame{ some code }


Behind the scenes is in reality a while loop with a sys.waitframe already included.

Also all functions with a loop, meant to run for a long time, when called on init() or main() should use the thread keyword before the name, like so -  thread funcName();
This is so your loop runs on a different thread and lets other game code run at the same time, if not it can "clog the pipeline" and make stuff slow. 

bitterman

#12
Thanks.

Now I have an idea.

/*
==================
idPlayer::Event_GetButtons
==================
*/
void idPlayer::Event_GetButtons( void ) {
idThread::ReturnInt( usercmd.buttons );
}


https://github.com/id-Software/DOOM-3/blob/master/neo/game/Player.cpp

Perhaps it will be more flexible if it will returns impulse, but there is some type mismath problems.

class usercmd_t {
public:
int gameFrame; // frame number
int gameTime; // game time
int duplicateCount; // duplication count for networking
byte         buttons; // buttons
signed char forwardmove; // forward/backward movement
signed char rightmove; // left/right movement
signed char upmove; // up/down movement
short angles[3]; // view angles
short mx; // mouse delta x
short my; // mouse delta y
signed char      impulse; // impulse command
byte         flags; // additional flags
int sequence; // just for debugging


/*
================
idThread::ReturnString
================
*/
void idThread::ReturnString( const char *text ) {
gameLocal.program.ReturnString( text );
}


Note that 'signed char impulse' not compatible with 'const char *text'.

Btw in D3BFG 'impulse' is a byte, perhaps it will be works with minimal changes

idThread::ReturnInt( usercmd.impulse );

instead:

idThread::ReturnInt( usercmd.buttons );

argoon

Yes to return impulses you just replicate the buttons code.

First you need to make a way for the script engine to read them by creating a script event


const idEventDef EV_Player_GetImpulses( "getImpulses", NULL, 'd' ); // "getImpulses" is the func name of your script event, NULL just tells we don't pass anything to the func, 'd' means we return a integer

EVENT( EV_Player_GetImpulses, idPlayer::Event_GetImpulses)

/*
==================
idPlayer::Event_GetImpulses
==================
*/
void idPlayer::Event_GetImpulses(void) {
idThread::ReturnInt(usercmd.impulse);
}



Then you create a script func on the doom_events.script file or your own file (you need to call your file on the doom_main.script for it to work).

scriptEvent    float   getImpulses();

To test the func and know what impulses you have active in what keys you can do the following:

call that on the player script

eachFrame
{
float impulse;

impulse = self.getImpulses();

sys.println("You used Impulse: " + impulse );
}