Doubletap Problem

Gtuner IV general support. Operation, questions, updates, feature request.

Doubletap Problem

Postby goathier » Fri Apr 26, 2019 8:45 pm

Hello, I am having problem with doubletap
Ive found a script that recognise doubletap for a single button but when I want to set another action for another button, everyting get messed.

As an exemple, I want that when i DoubleTap X, it runs RumbleNotifier and when i DT Y, it runs RumbleNotifier2.
Later I will surely want to DT B to run RumbleNotifier3 heh

Single Button that works: When I doubletap X, it runs RumbleNotifier
Code: Select all
 
#include <titanone.gph>
#pragma METAINFO("<author_name>", 1, 0, "")
///DOUBLETAP SPECS
int Double_Tap_Gap = 150;
//Don't change these
int Button_State = 0;
int Button_Timing;
//END OF DOUBLETAP
 
main {
 
if (DoubleTap(XB1_X)==TRUE){combo_run(RumbleNotifier);}
 
 
 
}          ///////////////////END OF MAIN/////////////////////////
 
combo RumbleNotifier {
    set_rumble(RUMBLE_LT, 1);
    wait(150);
    set_rumble(RUMBLE_LT, 0);
    wait(50);
}
 
 
 
function DoubleTap(Button) {
    // Detect Double-Tap
 
    if(Button_State == 0) {
        if(get_val(Button))Button_State = 1;
    } else if(Button_State == 1) {
        if(!get_val(Button)) { Button_Timing = 0; Button_State = 2; }
    } else if(Button_State == 2) {
        if(get_val(Button)) { Button_State = 1; return TRUE; }
        Button_Timing = Button_Timing + get_rtime();
        if(Button_Timing > Double_Tap_Gap) Button_State = 0;
            }
}
 


Adding doubletap Y to run RumbleNotifier2 will mess the script up. I only have to press once to run the combo

Code: Select all
 
#include <titanone.gph>
#pragma METAINFO("<author_name>", 1, 0, "")
///DOUBLETAP SPECS
int Double_Tap_Gap = 150;
//Don't change these
int Button_State = 0;
int Button_Timing;
//END OF DOUBLETAP
main {
if (DoubleTap(XB1_X)==TRUE){combo_run(RumbleNotifier);}
if (DoubleTap(XB1_Y)==TRUE){combo_run(RumbleNotifier2);}
 
 
 
}          ///////////////////END OF MAIN/////////////////////////
 
 
 
 
combo RumbleNotifier {
    set_rumble(RUMBLE_LT, 1);
    wait(150);
    set_rumble(RUMBLE_LT, 0);
    wait(50);
}
 
combo RumbleNotifier2 {
    set_rumble(RUMBLE_RT, 10);
    wait(100);
    set_rumble(RUMBLE_RT, 0);
    wait(200);
      set_rumble(RUMBLE_RT, 10);
    wait(100);
    set_rumble(RUMBLE_RT, 0);
    wait(50);
}
 
function DoubleTap(Button) {
    // Detect Double-Tap
 
    if(Button_State == 0) {
        if(get_val(Button))Button_State = 1;
    } else if(Button_State == 1) {
        if(!get_val(Button)) { Button_Timing = 0; Button_State = 2; }
    } else if(Button_State == 2) {
        if(get_val(Button)) { Button_State = 1; return TRUE; }
        Button_Timing = Button_Timing + get_rtime();
        if(Button_Timing > Double_Tap_Gap) Button_State = 0;
            }
}
 


Also tried this but this doesnt make the combo run.
Code: Select all
if(event_active(XB1_X) && time_release(XB1_X) < 250) {combo_run(RumbleNotifier);}
 



Ive also found some other scripts that are similar to Function DoubleTap(Button) but I would need to have many lines by button..

Is there anyway to get the DoubleTap(Button) Function to work for more than one button ?


TANKS !
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm

Re: Doubletap Problem

Postby Scachi » Sat Apr 27, 2019 8:57 am

Your last one should work fine, are your sure your rumble combos are working correctly ?

Try this, no need for the #include <titanone.gph> in this one:
Code: Select all
#include <xb1.gph> // for the xbox button names in addition the gpc designators like BUTTON_nr , press F1 to see the list
 
main {
    if(event_active(XB1_X) && time_release(XB1_X) < 250) {combo_run(RumbleNotifier);}
    if(event_active(XB1_Y) && time_release(XB1_Y) < 250) {combo_run(RumbleNotifier2);}
} 
 
combo RumbleNotifier {
    //      motor, strenght, time
    ffb_set(FFB_1, 20.0, 250); wait(0);
    wait(500);
  ffb_reset();
}
 
combo RumbleNotifier2 {
    //      motor, strenght, time
    ffb_set(FFB_1, 40.0, 250); wait(0);
    wait(500);
    ffb_set(FFB_1, 40.0, 250); wait(0);
    wait(500);
  ffb_reset();
}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Doubletap Problem

Postby goathier » Sat Apr 27, 2019 7:23 pm

Thanks a lot for the reply, I dont really get how but you got it working.
I added your XB1.gph and changed my rumble combos. I did not take the titanone.gph out but my whole thing is now working.
Thanks again ! :smile0517:
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm

Re: Doubletap Problem

Postby goathier » Sat Apr 27, 2019 8:36 pm

Hmhm but it seems like including XB1.gph messes my event_release actions ?
Could XB1.gph interfere with titanone.gph ?
Where I remove titanone.gph inclusion event_release stop working
In fact, my whole script messes up if I remove titanone.gph..

Any thoughts ?
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm

Re: Doubletap Problem

Postby Scachi » Sat Apr 27, 2019 9:20 pm

goathier wrote:Hmhm but it seems like including XB1.gph messes my event_release actions ?
Could XB1.gph interfere with titanone.gph ?
Where I remove titanone.gph inclusion event_release stop working
In fact, my whole script messes up if I remove titanone.gph..

Any thoughts ?

Get rid of the titanone header #include..that is only needed when you want to run T1 scripts on the T2. Stick to gpc2/titan two code and you will have no trouble.

The titanone.gph already has xb1 button names in it..if you use the xb1 header file in combination with it it will mess up the button identifiers.

For scripting information with examples for the T2 take a look at the wiki pages:
https://www.consoletuner.com/wiki/index ... _scripting

Post your whole script (or pm it to me if you want to keep it private) if you have trouble with converting it to plain T2/gpc2 code.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Doubletap Problem

Postby goathier » Sun Apr 28, 2019 6:56 pm

Thanks again for the reply, you're the man.

At first I took out titanone.gph inclusion as you mentionned. I kept the xb1.gph inclusion.
Got many errors because I am using/editing this script since T1 and barely havent changed the way I script. I am far from a pro and learnt on my own. I can get to where I want but its a pretty chaotic road. You'd probably laugh seeing my lines.

Most of my errors were caused by values not having .0
T1
Code: Select all
get_val(XB1_RT)==100

T2
Code: Select all
get_val(XB1_RT)==100.0


Then I had to get some #defines from titanone.gph to counter remaining errors.
Here's what I kept from titanone.gph
Code: Select all
const uint8 _ot_i[] = { // Titan One to Titan Two input index conversion table
    BUTTON_1BUTTON_2BUTTON_3BUTTON_4BUTTON_5BUTTON_6,
    BUTTON_7BUTTON_8BUTTON_9STICK_1_X, STICK_1_Y, STICK_2_X,
    STICK_2_Y, BUTTON_10, BUTTON_11, BUTTON_12, BUTTON_13, BUTTON_14,
    BUTTON_15, BUTTON_16, BUTTON_17, ACCEL_1_X, ACCEL_1_Y, ACCEL_1_Z,
    GYRO_1_XGYRO_1_YGYRO_1_ZBUTTON_18, POINT_1_X, POINT_1_Y,
    BUTTON_19, BUTTON_20, BUTTON_21, ACCEL_2_X, ACCEL_2_Y, ACCEL_2_Z
};
#define get_ptime(i)            time_active(_ot_i[i])
#define block(i, t)             inhibit(_ot_i[i], t)
#ifndef DISABLE_IRAND
int irand(int vmin, int vmax) {
    return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);
}
#endif /* DISABLE_IRAND */
 


Made some adjustments around get_ptime vs time_active events and now it seems like my lines are going straight forward.


Thanks again
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm

Re: Doubletap Problem

Postby Scachi » Sun Apr 28, 2019 7:06 pm

get_val on Titan One return an int numner , like : 14
get_val on Titan Two has more precision and returns fix32 numbers, this is why you need to add .0 , like : 14.0

Remove the T1 > T2 mappings..that will make problems with the xb1 header file.
If you use the xb1 header file all the xb1 names do already match the correct button_index number on the T2, no need for any conversion.

search and replace through your script (I would do this just to have your code in real gpc2 syntax)
get_ptime -> time_active
block -> inhibit
or use #defines without the "button mapping":
Code: Select all
 
#define get_ptime(i)            time_active(i)
#define block(i, t)             inhibit(i, t)
 


The irand function is fine , keep that.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Doubletap Problem

Postby goathier » Sun Apr 28, 2019 7:32 pm

I'll be out of thanks soon, but thanks again.

I'll keep old syntax active for those two but I'll try to learn that T2 language. But man it is very different, it digs much deeper and looks way more complicated :innocent_smile_1:
I still get that most of the T1 syntax haven't changed, just some events that were improved. But those bools and fix32 are unknown for me.
Here's my monster if you're a bit curious. Dont bother trying to improve it, I am not posting it in that purpose.
and.. TANKS !

Code: Select all
 
#pragma METAINFO("MyOwn", 1, 0, "PA")
#include <xb1.gph> // for the xbox button names in addition the gpc designators like BUTTON_nr , press F1 to see the list
#define get_ptime(i)            time_active(i)
#define block(i, t)             inhibit(i, t)
 
////////////////////////////////////////////
//////////////////IRAND/////////////////////
#ifndef DISABLE_IRAND
int irand(int vmin, int vmax) {
    return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);
}
#endif /* DISABLE_IRAND */
//////////////////IRAND/////////////////////
////////////////////////////////////////////
 
int aimassist;
int loopm;
int loopf;
int trigger;
int trigger2;
int trigger3;
int trigger4;
int primary;
int secondary;
int third;
int super;
int secondaryon;
int primaryon;
int crouch;
int aimp1=0;
int aimp3=0;
int aims1=0;
int aims3=0;
int aimt1=0;
int aimt3=0;
int ison;
 
 
main {
 
if (get_val(XB1_LT) && event_release(XB1_UP)){
    if (primary==1){
        aimp1=aimp1+5;
        combo_run(RumbleNotifier);
    } else if (secondary==1){
        aims1=aims1+5;   
        combo_run(RumbleNotifier);
    } else if (third==1){
        aimt1=aimt1+5;
        combo_run(RumbleNotifier);
    }
}   
 
if (get_val(XB1_LT) && event_release(XB1_DOWN)){
    if (primary==1){
        aimp1=aimp1-5;
        combo_run(RumbleNotifier2);
    } else if (secondary==1){
        aims1=aims1-5;
        combo_run(RumbleNotifier2);
    } else if (third==1){
        aimt1=aimt1-5;
        combo_run(RumbleNotifier2);
    }
}   
 
if (get_val(XB1_LT) && event_release(XB1_RIGHT)){
    if (primary==1){
        aimp3=aimp3+5;
        combo_run(RumbleNotifier);
    } else if (secondary==1){
        aims3=aims3+5;
        combo_run(RumbleNotifier);
    } else if (third==1){
        aimt3=aimt3+5;
        combo_run(RumbleNotifier);
    }
}   
 
if (get_val(XB1_LT) && event_release(XB1_LEFT)){
    if (primary==1){
        aimp3=aimp3-5;
        combo_run(RumbleNotifier2);
    } else if (secondary==1){
        aims3=aims3-5;
        combo_run(RumbleNotifier2);
    } else if (third==1){
        aimt3=aimt3-5;
        combo_run(RumbleNotifier2);
    }
}   
 
 
 if((event_active(XB1_X) && time_release(XB1_X) < 200) && !CheckX && !CheckX2 && !CheckX3){
combo_run(CheckX);
 }
 
 
if (event_release(XB1_LS) && get_ptime(XB1_LS)>200 && get_val(XB1_X)){
    if (!aimassist){
        aimassist=1;
        aimp1=0;
        aimp3=0;
        aims1=0;//21;
        aims3=0;
        aimt1=0;//21;
        aimt3=0;;
        combo_run(RumbleNotifier);
    }else{
        aimassist=0;
        combo_run(RumbleNotifier2);
    }
}
 
if ((event_active(XB1_RS) && time_release(XB1_RS) < 250 )||(event_release(XB1_RS)&&(get_val(XB1_RT) || get_val(XB1_LT)))) {
    if (primary) {
        combo_run(gosec);
        combo_run(RumbleNotifier2);
    }else if (secondary||third){
        combo_run(gop);
        combo_run(RumbleNotifier);
    }
}
 
if (event_release(XB1_LS)&&get_ptime(XB1_LS)>200 && get_val(XB1_B)){
    if (!crouch){
        crouch=1;
        combo_run(RumbleNotifier);
    }else{
        crouch=0;
        combo_run(RumbleNotifier2);
    }
}
 
if (get_val(XB1_LT) && crouch==1){
block(XB1_LS,1000);
    if ((get_ptime(XB1_LS)>50) && event_release(XB1_LS)  && !lscrouch){
        combo_run(lscrouch);
    }
}
 
if (loopm) {combo_run(switchm);}   
if (!loopm) {combo_stop(switchm);}
if (loopf) {combo_run(switchf);}           
if (!loopf) {combo_stop(switchf);}
 
if (get_val(XB1_DOWN) && event_release(XB1_B) ){
combo_run(setson);
    if (!loopf) {
        combo_run(startf);
    }
}
 
if (get_val(XB1_DOWN) && event_release(XB1_X)){
combo_run(setpon);
    if (!loopf) {
        combo_run(startf);
    }
}
 
if (event_release(XB1_RS) && get_ptime(XB1_RS)>1000 && !(get_val(XB1_RT)||get_val(XB1_X))) {
    if (!loopf) {
        combo_run(startf);
    }else if (loopf) {
        combo_run(stopf);
    }
}
 
 
if  (((event_release(XB1_RS) && get_val(XB1_RB))||(get_val(XB1_RB)&&event_release(XB1_X) && get_ptime(XB1_X)>500))&& !(startm || stopm)){// && busy==0) {
    if (!loopm) {
        combo_run(startm);
    }else if (loopm) {
        combo_run(stopm);
    }
}
 
 
if (event_release(XB1_Y) ){
    if ((time_active(XB1_Y)>300)&&(primary==1||secondary==1)){
        combo_run(gothird);
        combo_run(RumbleNotifier);
        combo_run(RumbleNotifier2);
        combo_run(RumbleNotifier2);
        combo_run(RumbleNotifier);
        combo_run(RumbleNotifier);
    }else if (third==1){
        combo_run(RumbleNotifier);
        combo_run(gop);
    }else if ((time_active(XB1_Y)<300)&&primary==1) {
        combo_run(RumbleNotifier2);
        combo_run(gosec);
     }else if ((time_active(XB1_Y)<300)&&secondary==1) {
        combo_run(RumbleNotifier);
        combo_run(gop);
    }
}
 
if (loopf==1 && aimassist==1 && !aim && get_val(XB1_RT)==100.0  && (get_val(XB1_RY)<20.0) && (get_val(XB1_RY)>-20.0)&& (get_val(XB1_RX)<10.0) && (get_val(XB1_RX)>-10.0) )  {//!(get_val(XB1_RY)<20 && get_val(XB1_RY)>-20) || (!XB1_RX<20 || !XB1_RX>-20)) {
    if (ison==0 || trigger3==0){
        ison=1;
        if (primary==1){
        trigger3=irand(aimp1-5,aimp1+5);
        trigger4=irand(aimp3-5,aimp3+5);
            if (trigger3>100) {trigger3=100;}
            if (trigger4>100) {trigger4=100;}
        }else if (secondary==1){
            trigger3=irand(aims1-5,aims1+5);
            trigger4=irand(aims3-5,aims3+5);
            if (trigger3>100) {trigger3=100;}
            if (trigger4>100) {trigger4=100;}
        }else if (third==1){
            trigger3=irand(aimt1-5,aimt1+5);
            trigger4=irand(aimt3-5,aimt3+5);
            if (trigger3>100) {trigger3=100;}
            if (trigger4>100) {trigger4=100;}
        }
        combo_run(aim2);
//combo_run(aim3);
    }
combo_run(aim);
combo_run(aim1);
//}else{   
//    set_val(STICK_1_Y, 0);
}
 
 
} /////////////////////////////////THIS ONE ENDS MAIN/////////////////////////////
 
 
//////////////////////////////////COMBOS STARTS HERE///////////////////////////////////
combo aim{
    if ((primary && aimp3) || (secondary && aims3) || (third && aimt3)){
        if (trigger3>100) {trigger3=100;}
        if (trigger4>100) {trigger4=100;}
        set_val(STICK_1_X, trigger4); //trigger2);
        set_val(XB1_RX, trigger4); //trigger2);
    }
}
combo aim1{
    if ((primary && aimp1) || (secondary && aims1) || (third && aimt1)){
        if (trigger3>100) {trigger3=100;}
        if (trigger4>100) {trigger4=100;}
        set_val(STICK_1_Y, trigger3); //trigger2);
        set_val(XB1_RY, trigger3); //trigger2);
    }
}
combo aim2{
wait(irand(213,321));
ison=0;
}
 
 
combo lscrouch{
set_val(XB1_B, 100);
wait(50);
set_val(XB1_B,0);
wait(250);
}
 
combo gop{
primary=1;
secondary=0;
third=0;
}
combo gosec{
primary=0;
secondary=1;
third=0;
}
combo gothird{
primary=0;
secondary=0;
third=1;
}
combo fakeweapon{
primary=0;
secondary=0;
third=0;
}   
 
combo CheckX1{
}   
 
combo CheckX{
wait(50);
    if (primaryon){
        combo_run(RumbleNotifier);
 
    }else if (!(primaryon)){
        combo_run(RumbleNotifier2);
    }
combo_run(CheckX2);
}
 
combo CheckX2{
wait(1000);
    if (secondaryon){
        combo_run(RumbleNotifier);
    }else if (!(secondaryon )){
        combo_run(RumbleNotifier2);
    }
    combo_run(CheckX3);
}
 
combo CheckX3{
wait(1000);
    if (loopm){
        combo_run(RumbleNotifier);
    }else if (!(loopm )){
        combo_run(RumbleNotifier2);
    }
}
 
 
combo setpon{
wait(100);
    if (primaryon==0){
        primaryon=1;
        combo_run(RumbleNotifier);
    }else if (primaryon==1){
        primaryon=0;
        combo_run(RumbleNotifier2);
    }
//wait(100)
}
 
combo setson{
wait(100);
    if (!secondaryon){
        secondaryon=1;
        combo_run(RumbleNotifier);
 
    }else if (secondaryon==1){
        secondaryon=0;
        combo_run(RumbleNotifier2);
    }
}
 
 
 
 
combo startf {
wait(100);
    if (!stopf){
        combo_run(RumbleNotifier);
        loopf=1;
        combo_run(gop);
    }
wait(100);
}
 
combo stopf {
    //loopm=0;
wait(100);
    if (!startf){
        combo_run(RumbleNotifier2);
        loopf=0;
    }
wait(100);
}
 
combo switchf {
    if ((get_val(XB1_RT)==100.00) && !turbofire/*&& !NLB1*/ && ((primary==1 && primaryon==1) || (secondary==1 && secondaryon==1))) {combo_run (turbofire);}   
}
 
combo turbofire {
trigger=irand(140, 180);
set_val(XB1_RT,100);
wait(trigger);//(irand(50,1000));
trigger=irand(45, 55);
set_val(XB1_RT,0);                 
wait(trigger); //irand(50,1000));             
}
 
combo startm {
wait(100);
    if (!stopm){
        loopm=1;
        combo_run(RumbleNotifier);
    //loopf=1;
    }
wait(100);
    //busy=0;
}
 
combo stopm {
wait(100);
    if(!startm){
        combo_run(RumbleNotifier2);
        loopm=0;
    }
wait(100);
   // busy=0;
}
 
combo switchm {
    if (get_val(XB1_RB)) {combo_run (turbomelee);}   
}
 
combo turbomelee {                         
trigger=irand(120, 150);
set_val(XB1_RB,100);     
wait(trigger);//(irand(50,1000));
trigger=irand(45, 60);
set_val(XB1_RB,0);                 
wait(trigger);//(irand(50,1000));     
}
 
 
 
 
combo RumbleNotifier {
    //      motor, strenght, time
    ffb_set(FFB_1, 20.0, 150); wait(0);
    wait(250);
  ffb_reset();
}
 
combo RumbleNotifier2 {
    //      motor, strenght, time
    ffb_set(FFB_2, 20.0, 150); wait(0);
    wait(250);
    ffb_set(FFB_2, 20.0, 150); wait(0);
    wait(250);
  ffb_reset();
}
 
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm

Re: Doubletap Problem

Postby Scachi » Sun Apr 28, 2019 8:02 pm

:smile0517:

only thing I see at a quick read that looks strange is
Code: Select all
 
if (event_release(XB1_Y) ){
    if ((time_active(XB1_Y)>300)&&(primary==1||secondary==1)){
        combo_run(gothird);
        combo_run(RumbleNotifier);
        combo_run(RumbleNotifier2);
        combo_run(RumbleNotifier2);
        combo_run(RumbleNotifier);
        combo_run(RumbleNotifier);
    }else if (third==1){
 

combo_run will start a combo if it is not already running, it will make no difference how often you put the same combo name in there.. I think this will produce the same result:
Code: Select all
 
if (event_release(XB1_Y) ){
    if ((time_active(XB1_Y)>300)&&(primary==1||secondary==1)){
        combo_run(gothird);
        combo_run(RumbleNotifier);
        combo_run(RumbleNotifier2);
    }else if (third==1){
 


For more information on datatypes bool/fix32/.. T2: https://www.consoletuner.com/wiki/index ... data_types
and for how to understand the language reference/GPC IDE information when you enter a function name in GTuner IV so you see which datatype is used/returned:
https://www.consoletuner.com/wiki/index ... :functions
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Doubletap Problem

Postby goathier » Sun Apr 28, 2019 9:48 pm

I never really realised those dupes, it shaked anyway hah!
I took it out and replaced it. Now I've got more control.

Thanks for letting me make my way!
User avatar
goathier
Sergeant
Sergeant
 
Posts: 7
Joined: Mon Jan 16, 2017 6:29 pm


Return to Gtuner IV Support

Who is online

Users browsing this forum: No registered users and 66 guests