if condition not working

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

if condition not working

Postby Derivates » Sat Mar 30, 2019 5:56 pm

This is my script:
Code: Select all
main {
    if(is_active(BUTTON_8) && is_release(BUTTON_9) && event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}
combo cLeanLeft {
    set_val(BUTTON_6, 100.00);
    wait(110);
    set_val(BUTTON_9, 100.00);
    wait(110);
}
 

I wanted the combo to run once so I swapped is_active to event_active for BUTTON_5 (worked), BUT the second condtion (BUTTON_9) is not being taken into account. The script should work like this:

BUTTON_8 (HOLD) + BUTTON_9 (just press, that's why I'm using release) + BUTTON_5 (press) (run combo once).

It should only work if those conditions are met, but somehow if I press BUTTON_8 + BUTTON_5 it still runs the combo (and BUTTON_9 is not being taken into consideration).

Help is appreciated.

EDIT: I fond the error after some time, it's actually executing the combo because the is_release statement is TRUE because the BUTTON_9 is INDEED released, but how would I make it so it only works if I press BUTTON_9 then release and then the rest of the condition?

It should somehow be something like this:
Code: Select all
main {
    if(is_active(BUTTON_8) && event_active(BUTTON_9) && event_release(BUTTON_9)&& event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Re: if condition not working

Postby Buffy » Sat Mar 30, 2019 7:21 pm

Instead of event_release(BUTTON_9) use time_release(BUTTON_9) < 200, also it's pretty much impossible for 2 buttons to trigger event_active at the same time.

Code: Select all
 
main {
    if(is_active(BUTTON_8) && (check_active(BUTTON_9, 200) && time_release(BUTTON_9) < 200) && event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}
 
ConsoleTuner Support Team || Discord || Custom Scripts
User avatar
Buffy
Lieutenant
Lieutenant
 
Posts: 422
Joined: Wed Jul 20, 2016 5:23 am

Re: if condition not working

Postby Derivates » Sat Mar 30, 2019 9:15 pm

Buffy wrote:Instead of event_release(BUTTON_9) use time_release(BUTTON_9) < 200, also it's pretty much impossible for 2 buttons to trigger event_active at the same time.

Code: Select all
 
main {
    if(is_active(BUTTON_8) && (check_active(BUTTON_9, 200) && time_release(BUTTON_9) < 200) && event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}
 

Tried it, but it's no completing the if statement, the combo isn't running at all; the conditions are never met.
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Re: if condition not working

Postby Buffy » Sat Mar 30, 2019 10:21 pm

Sorry, try this instead:

Code: Select all
 
#include <XB1.gph>
 
main {
    if(is_active(XB1_LT) && is_active(XB1_LS) && time_release(XB1_LS) < 400 && event_active(XB1_RT)) {
        combo_run(cLeanLeft);
    }
}
 
ConsoleTuner Support Team || Discord || Custom Scripts
User avatar
Buffy
Lieutenant
Lieutenant
 
Posts: 422
Joined: Wed Jul 20, 2016 5:23 am

Re: if condition not working

Postby Derivates » Tue Apr 02, 2019 10:24 pm

Buffy wrote:Sorry, try this instead:

Code: Select all
 
#include <XB1.gph>
 
main {
    if(is_active(XB1_LT) && is_active(XB1_LS) && time_release(XB1_LS) < 400 && event_active(XB1_RT)) {
        combo_run(cLeanLeft);
    }
}
 

Sorry for the late reply I've been very busy, the script still doesn't do anything, I'm trying with all the possible ways to execute this, but no action. @J2KBr maybe???
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Re: if condition not working

Postby Buffy » Wed Apr 03, 2019 2:40 am

I guess I'm not fully understanding this part where you phrase it

"BUTTON_8 (HOLD) + BUTTON_9 (just press, that's why I'm using release) + BUTTON_5 (press) (run combo once)."

The conditions are:
button 8 held + button 9 activated within the last 200 ms (and is still held?) + button 5 just activated? If so, the code would be

Code: Select all
main {
    if(is_active(BUTTON_8) && (is_active(BUTTON_9) && time_active(BUTTON_9) < 200) && event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}

combo cLeanLeft {
    set_val(BUTTON_6, 100.00);
    wait(110);
    set_val(BUTTON_9, 100.00);
    wait(110);
}
ConsoleTuner Support Team || Discord || Custom Scripts
User avatar
Buffy
Lieutenant
Lieutenant
 
Posts: 422
Joined: Wed Jul 20, 2016 5:23 am

Re: if condition not working

Postby bonefisher » Wed Apr 03, 2019 3:24 am

Code: Select all
 
main {
    if(is_active(BUTTON_8)){
        if(is_active(BUTTON_9) && event_active(BUTTON_5)) {
            combo_run(cLeanLeft);
        }
    }
}
combo cLeanLeft {
    set_val(BUTTON_6, 100.00);
    wait(110);
    set_val(BUTTON_9, 100.00);
    wait(110);
}
 
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: if condition not working

Postby DontAtMe » Wed Apr 03, 2019 5:26 am

maybe this ? :unsure:
Code: Select all
main {
  if(is_active(BUTTON_8)){
    if(event_active(BUTTON_5)){
       cLeanLeft = is_active(BUTTON_9);
      cLeanRight = is_active(BUTTON_6);
    } 
  }
}
combo cLeanLeft {
  wait(110);
  set_val(BUTTON_6, 100);
  set_val(BUTTON_9, 0);
  wait(110);
}
combo cLeanRight {
  wait(110);
  set_val(BUTTON_9, 100);
  set_val(BUTTON_6, 0);
  wait(110);
}


Edit: Actually I think I understand what the OP is asking for.
I had to read thru the previous posts a couple more times, I am pretty sure this is what he's trying to do

@Derivates give this last script a try.
Code: Select all
 main {
  uint32 timer;
 
//---
   if(is_active(BUTTON_8)){
    timer+=elapsed_time();
    if(event_active(BUTTON_6) || event_active(BUTTON_9)) timer = 0;
    if(event_active(BUTTON_5) && (is_release(BUTTON_6) && is_release(BUTTON_9))){
       cLeanLeft = !check_release(BUTTON_9, timer);
      cLeanRight = !check_release(BUTTON_6, timer);
    }
  } else timer = 0;
//---
 
}
 
combo cLeanLeft {
  set_val(BUTTON_6, 100);
  wait(110);
  set_val(BUTTON_9, 100);
  wait(110);
}
combo cLeanRight {
  set_val(BUTTON_9, 100);
  wait(110);
  set_val(BUTTON_6, 100);
  wait(110);
}
User avatar
DontAtMe
Captain
Captain
 
Posts: 502
Joined: Tue Oct 02, 2018 4:49 am

Re: if condition not working

Postby Derivates » Thu Apr 18, 2019 4:51 pm

Buffy wrote:I guess I'm not fully understanding this part where you phrase it

"BUTTON_8 (HOLD) + BUTTON_9 (just press, that's why I'm using release) + BUTTON_5 (press) (run combo once)."

The conditions are:
button 8 held + button 9 activated within the last 200 ms (and is still held?) + button 5 just activated? If so, the code would be

Code: Select all
main {
    if(is_active(BUTTON_8) && (is_active(BUTTON_9) && time_active(BUTTON_9) < 200) && event_active(BUTTON_5)) {
        combo_run(cLeanLeft);
    }
}

combo cLeanLeft {
    set_val(BUTTON_6, 100.00);
    wait(110);
    set_val(BUTTON_9, 100.00);
    wait(110);
}

Didn't work, but last response did. Thanks for your help and pardon the late response.
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Re: if condition not working

Postby Derivates » Thu Apr 18, 2019 4:53 pm

bonefisher wrote:
Code: Select all
 
main {
    if(is_active(BUTTON_8)){
        if(is_active(BUTTON_9) && event_active(BUTTON_5)) {
            combo_run(cLeanLeft);
        }
    }
}
combo cLeanLeft {
    set_val(BUTTON_6, 100.00);
    wait(110);
    set_val(BUTTON_9, 100.00);
    wait(110);
}
 

Didn't work, but last response did. Thanks for your help and pardon the late response.
User avatar
Derivates
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Sat Jan 19, 2019 6:15 pm

Next

Return to GPC2 Script Programming

Who is online

Users browsing this forum: midg3t2 and 76 guests