Author Topic: getButtons  (Read 881 times)

0 Members and 1 Guest are viewing this topic.

Bladeghost

  • Jr. Member
  • **
  • Posts: 67
  • Karma: +13/-1
  • idTech4 Mod Artist
    • View Profile
getButtons
« on: February 03, 2015, 08:54:47 PM »
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.
« Last Edit: February 03, 2015, 08:58:52 PM by Bladeghost »

Radegast

  • Newbie
  • *
  • Posts: 27
  • Karma: +3/-1
  • Alpha Labs scientist
    • View Profile
    • ET: Legacy
Re: getButtons
« Reply #1 on: February 19, 2015, 05:38:35 AM »
These buttons are available in the BFG edition:

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

argoon

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +21/-80
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #2 on: March 23, 2017, 01:38:28 PM »
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

  • Hero Member
  • *****
  • Posts: 959
  • Karma: +74/-127
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: getButtons
« Reply #3 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.

MrC

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +8/-24
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #4 on: March 24, 2017, 03:35:03 PM »
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

  • Hero Member
  • *****
  • Posts: 959
  • Karma: +74/-127
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: getButtons
« Reply #5 on: March 25, 2017, 12:49:32 PM »
Why are you here?

To remind you about it  >:D

argoon

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +21/-80
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #6 on: March 26, 2017, 08:12:51 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

  • Sr. Member
  • ****
  • Posts: 250
  • Karma: +8/-5
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #7 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.

The Happy Friar

  • Happy Happy Joy Joy
  • Administrator
  • Hero Member
  • *****
  • Posts: 851
  • Karma: +41/-4
  • Semi-Newbie.
    • View Profile
    • EarthQuake
Re: getButtons
« Reply #8 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
Code: [Select]
bind h "trigger scriptfunction"
Pretty sure "trigger" will activate a script function.

argoon

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +21/-80
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #9 on: August 26, 2017, 02:36:17 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.

Code: [Select]

//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
Code: [Select]
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?
« Last Edit: August 26, 2017, 02:48:02 PM by argoon »

bitterman

  • Sr. Member
  • ****
  • Posts: 250
  • Karma: +8/-5
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #10 on: August 26, 2017, 10:26:21 PM »
Quote
Pretty 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:

Code: [Select]
void main() {thread isPressed()}

void isPressed() {

while(1) {

(some check via argoon's modwiki link)

sys.waitFrame() // error without it

}
}
« Last Edit: August 26, 2017, 11:16:10 PM by bitterman »

argoon

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +21/-80
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #11 on: August 27, 2017, 09:38:59 AM »
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:

Code: [Select]
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

  • Sr. Member
  • ****
  • Posts: 250
  • Karma: +8/-5
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #12 on: August 27, 2017, 11:36:29 AM »
Thanks.

Now I have an idea.

Code: [Select]
/*
==================
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.

Code: [Select]
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

Code: [Select]
/*
================
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 );
« Last Edit: August 27, 2017, 12:00:36 PM by bitterman »

argoon

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +21/-80
  • Doom Newbie
    • View Profile
Re: getButtons
« Reply #13 on: August 27, 2017, 04:14:57 PM »
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

Code: [Select]
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
Code: [Select]
eachFrame
{
float impulse;

impulse = self.getImpulses();

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