Help with double tap

GPC2 script programming for Titan Two. Code examples, questions, requests.

Help with double tap

Postby Sightblinder » Sun Oct 13, 2019 8:43 am

Hi
Love this community!

I would like some assistance with a script.
I have a xbox elite controller and use the paddles for scripts. There are a total of 4 paddles wich means 4 combo scripts atm. I would like the expand this to 8 with double tap function.
This is how it looks today.
Code: Select all
main {
    if (event_active(BUTTON_20)) combo_run(combo1);    //left top
    if (event_active(BUTTON_19)) combo_run(combo2);    //right bottom
    if (event_active(BUTTON_18)) combo_run(combo3)//right top
    if (event_active(BUTTON_21)) combo_run(combo4);     //left bottom


And this is how i imagine the function but have no idea what functions/commands to use.
Code: Select all
main {
    if (event_active(BUTTON_20)) combo_run(combo1);    //left top  single tap
    if (event_active(BUTTON_20)) combo_run(combo5);    //left top  double tap
        if (event_active(BUTTON_19)) combo_run(combo2);    //right bottom single tap
    if (event_active(BUTTON_20)) combo_run(combo6);    //left top  double tap
        if (event_active(BUTTON_18)) combo_run(combo3)//right top single tap
    if (event_active(BUTTON_20)) combo_run(combo7);    //left top  double tap
        if (event_active(BUTTON_21)) combo_run(combo4);     //left bottom single tap
        if (event_active(BUTTON_20)) combo_run(combo8);    //left top  double tap
User avatar
Sightblinder
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Wed Jul 31, 2019 6:56 pm

Re: Help with double tap

Postby Mad » Sun Oct 13, 2019 9:27 am

Code: Select all
#define dtap_time 160
 
main {
  if (event_active(BUTTON_20)) combo_run(combo1);
  if (event_active(BUTTON_20) && time_release(BUTTON_20) < dtap_time) combo_run(combo5);
 
  if (event_active(BUTTON_19)) combo_run(combo2);
  if (event_active(BUTTON_19) && time_release(BUTTON_19) < dtap_time) combo_run(combo6);
 
  if (event_active(BUTTON_18)) combo_run(combo3);
  if (event_active(BUTTON_18) && time_release(BUTTON_18) < dtap_time) combo_run(combo7);
 
  if (event_active(BUTTON_21)) combo_run(combo4);
  if (event_active(BUTTON_21) && time_release(BUTTON_21) < dtap_time) combo_run(combo8);
}
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord (2K / FPS)
Mad
Major General
Major General
 
Posts: 4532
Joined: Wed May 22, 2019 5:39 am

Re: Help with double tap

Postby Sightblinder » Sun Oct 13, 2019 12:52 pm

Thank you.

The double tap only works when the normal tap is on cooldown. So i guess i need a delay for to check for double tap combo before triggering single tap?

Also what would the command be if im keeping it pressed. Maybe thats easier? So press (hold down) instead of double tap.

Again, ty very much
User avatar
Sightblinder
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Wed Jul 31, 2019 6:56 pm

Re: Help with double tap

Postby Scachi » Sun Oct 13, 2019 1:27 pm

You can use use "event_release" with "time_active" to run the combo depending on the hold time of the buttons.
It will trigger the combo then when you release the button.

Or use a mix, for short check it on release, for long check it with check_active().
this will alow the second combo to run/repeated as long as the button is held down.

Code: Select all
// release:
#define tap_time 160
 
main {
    if (event_release(BUTTON_20)) {
        if (time_active(BUTTON_20)<tap_time) combo_run(combo1);
        else combo_run(combo5);
    }
 
    if (event_release(BUTTON_19)) {
        if (time_active(BUTTON_19)<tap_time) combo_run(combo2);
        else combo_run(combo6);
    }
 
    if (event_release(BUTTON_18)) {
        if (time_active(BUTTON_18)<tap_time) combo_run(combo3);
        else combo_run(combo7);
    }
 
    if (event_release(BUTTON_21)) {
        if (time_active(BUTTON_21)<tap_time) combo_run(combo4);
        else combo_run(combo8);
    }
}
 
combo combo1 {printf("1");}
combo combo2 {printf("2");}
combo combo3 {printf("3");}
combo combo4 {printf("4");}
combo combo5 {printf("5");}
combo combo6 {printf("6");}
combo combo7 {printf("7");}
combo combo8 {printf("8");}
 



Code: Select all
// mix:
#define tap_time 160
 
main {
    if (event_release(BUTTON_20) && time_active(BUTTON_20)<tap_time) combo_run(combo1);
    if (check_active(BUTTON_20,tap_time)) combo_run(combo5);
 
 
    if (event_release(BUTTON_19) && time_active(BUTTON_19)<tap_time) combo_run(combo2);
    if (check_active(BUTTON_19,tap_time)) combo_run(combo6);
 
    if (event_release(BUTTON_18) && time_active(BUTTON_18)<tap_time) combo_run(combo3);
    if (check_active(BUTTON_18,tap_time)) combo_run(combo7);
 
    if (event_release(BUTTON_21) && time_active(BUTTON_21)<tap_time) combo_run(combo4);
    if (check_active(BUTTON_21,tap_time)) combo_run(combo8);
}
 
combo combo1 {printf("1");}
combo combo2 {printf("2");}
combo combo3 {printf("3");}
combo combo4 {printf("4");}
combo combo5 {printf("5");}
combo combo6 {printf("6");}
combo combo7 {printf("7");}
combo combo8 {printf("8");}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Help with double tap

Postby Sightblinder » Sun Oct 13, 2019 1:52 pm

Simply amazing, tytyty
User avatar
Sightblinder
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Wed Jul 31, 2019 6:56 pm

Re: Help with double tap

Postby Scachi » Sun Oct 13, 2019 2:34 pm

Sightblinder wrote:Simply amazing, tytyty

No problem.
Here is another solution. This one allows the executed combos (single press or double press) to be looped as long as the button is held down. Could be extended to 3 or more presses too:
Code: Select all
 
#define tap_time 150
uint8 taps;
 
main {
    taps=presses(BUTTON_20);
    if (taps==1) combo_run(combo1);
    if (taps>=2) combo_run(combo5);
 
    taps=presses(BUTTON_19);
    if (taps==1) combo_run(combo2);
    if (taps>=2) combo_run(combo6);
 
    taps=presses(BUTTON_18);
    if (taps==1) combo_run(combo3);
    if (taps>=2) combo_run(combo7);
 
    taps=presses(BUTTON_21);
    if (taps==1) combo_run(combo4);
    if (taps>=2) combo_run(combo8);
}
 
combo combo1 {printf("1");}
combo combo2 {printf("2");}
combo combo3 {printf("3");}
combo combo4 {printf("4");}
combo combo5 {printf("5");}
combo combo6 {printf("6");}
combo combo7 {printf("7");}
combo combo8 {printf("8");}
 
uint8 presses(uint8 btn) {
    static uint8 pressed[21];
    if (btn>20) return FALSE;
 
    if (event_active(btn)) pressed[btn]+=1;
 
    if (is_active(btn) && time_active(btn) > tap_time) return pressed[btn];
 
    if (!is_active(btn) && time_release(btn) > tap_time) {
        uint8 taps=pressed[btn];
        pressed[btn]=0;
        return taps;
    }
    return FALSE;
}
 
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 82 guests