Wait() in an if block in a combo

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

Wait() in an if block in a combo

Postby Liquidkhaos » Sun Nov 26, 2017 6:47 pm

I don't understand why these wait()s do not compile. :cry: Set up the basic structure of the code here. By the way searching for combo, wait, and if is almost as good as searching for everything lol. If I comment out the waits it compiles. If I create a combo that wait()s at the root level it works. Is this user error? :whistling:

Code: Select all
#define LongPress 300
#define Press 100
uint32 BigHitWait = 0;       
int32 minute = 60000;
main {
    combo_run (getBusy);
}
 
getBusy{
    combo_run (BigHit);
} 
 
combo BigHit {
     BigHitWait += elapsed_time();
    if(BigHitWait >= minute ) {
        BigHitWait = 0;
        set_val(L1, LongPress);
        set_val(Triangle, Press);
        wait(250);
        set_val(Triangle, Press);
        wait(500);
    }   
}
User avatar
Liquidkhaos
First Sergeant
First Sergeant
 
Posts: 61
Joined: Fri Sep 22, 2017 11:34 pm
Location: USA Tidewater Virginia

Re: Wait() in an if block in a combo

Postby Sillyasskid » Sun Nov 26, 2017 9:20 pm

I am assuming you are new to Scripting, with the GPC2 language.
The reason the script wont compile, is because:
Wait() functions cannot be nested and must only be used within a combo.

Now to address something else
Code: Select all
BigHitWait = 0;
        set_val(L1, LongPress);
        set_val(Triangle, Press);
        wait(250);
        set_val(Triangle, Press);
        wait(500);
Can you clarify what you were expecting to happen when this section of your script executed? because It does not make much sense to me.

The script is not written to produce any event, even if the compiler was fine with the wait() functions. There are still other issues with this script that should be addressed.

I can correct the script for you, that way it will be easier for me to address the other issues that I see. I just need to know how exactly you want need the script to do.
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Wait() in an if block in a combo

Postby Liquidkhaos » Sun Nov 26, 2017 11:43 pm

Thanks. I am new to scripting.

What I wanted to do Was create a L1 + Triangle Combo press then release and then L1 + Triangle Combo press again.

At the time of this question I thought it was L1 + Triangle Combo press then release and then Triangle press. My mistake though.

Currently I have moved the waits to the calling combo so as to not nest the wait()s. This is working fine now that they are not nested.
Code: Select all
 
uint32 ArtifactHitWait = 0;      // create a time gap for artifact power
int32 minute = 60000;
...
    ArtifactHitWait += elapsed_time();
    if(ArtifactHitWait >= minute ) {
        combo_run(ArtifactHit);
        ArtifactHitWait = 0; /* Reset Timer */
    }
...
 

and I am trying several variations of the following. Its still not right. :ashamed: The best results I can see that the first part is working but the second cord does not seem to happen. I made a test gpc with only this to try and figure out what I was screwing up without the rest of the script out of the equation.

Code: Select all
combo ArtifactHit {
    // Press L1 + O chord wait some and repress the  L1 + O chord
    set_val(L1, Press); //   L1 +
    set_val(O, Press); //    O
    wait(ShortWait); //      Hold chord for 250ms
 
    wait(ShortWait); //      250ms before next chord
 
    set_val(L1, Press); //   L1 +
    set_val(O, Press); //    O
    wait(ShortWait); //      Hold chord for 250ms
    wait(MedWait); //        Not sure this is needed ..
}
User avatar
Liquidkhaos
First Sergeant
First Sergeant
 
Posts: 61
Joined: Fri Sep 22, 2017 11:34 pm
Location: USA Tidewater Virginia

Re: Wait() in an if block in a combo

Postby Sillyasskid » Mon Nov 27, 2017 12:59 am

Code: Select all
#define L1                          BUTTON_7       
#define Triangle                    BUTTON_14
#define O                           BUTTON_15
#define ShortWait   (uint16)            250 //ms
#define PRESS       (uint16)           100 //int
#define minute      (uint16)        60000 //int
main
{
if(!LT_O)minutefunction();
}
combo LT_O // Press L1 + O chord wait some and repress the  L1 + O chord
{                       
  set_val(L1, PRESS), set_val(O, PRESS); wait(ShortWait);// L1 && O Active for 250ms
  wait(ShortWait);// 250ms before next chord
  set_val(L1, PRESS), set_val(O, PRESS); wait(ShortWait);// L1 && O Active for 250ms
  minutefunction();
}
void minutefunction()
{
  static uint32 p = system_time();
  if(system_time() - p >= minute) p = system_time(), combo_run(LT_O);
  return;
}
Let me know if this script works in the way you intended it to.
If so, then :smile0203:
If you need any clarification on something, just ask.I understand you are new.
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Wait() in an if block in a combo

Postby Liquidkhaos » Mon Nov 27, 2017 5:09 am

Thank you. :smile0517: I am wrapping my head around this now.

So If I am understanding the code here: if(!LT_O)minutefunction(); calls the minute function if LT_O is not currently running. minutefunction spins until a minute goes by then calls LT_O. LT_O is not called repeatedly because after minutefunction is called and in turn calls LT_O, minutefunction becomes 'part' of the LT_O process so once the cycle starts if(!LT_O) always returns false because LT_O is basically running until we issue a combo_stop etc.

With a combo named BigHit, whay cant you call it like this:
Code: Select all
if(!BigHit)BigHit();
User avatar
Liquidkhaos
First Sergeant
First Sergeant
 
Posts: 61
Joined: Fri Sep 22, 2017 11:34 pm
Location: USA Tidewater Virginia

Re: Wait() in an if block in a combo

Postby Sillyasskid » Mon Nov 27, 2017 8:35 am

Liquidkhaos wrote:if(!LT_O)minutefunction(); calls the minute function if LT_O is not currently running.

Correct.
Liquidkhaos wrote:if(!LT_O) always returns false because LT_O is basically running until we issue a combo_stop etc.
Here you are a bit confused.

I can break it down.
Step 1
As long as LT_O is not running
if(!LT_O)minutefuction() remains true.
minutefunction() calls LT_O, after 60 seconds.
-----------------------------------------------------------
Step2
LT_O runs,
if(!LT_O)minutefuction() remains false.
LT_O finishes,
-------------------------------------------------------------
Step 3
if(!LT_O)minutefuction() remains true
Back to Step 1

Think about it.
In order for LT_O to start. minutefuction() must be called for a minute.
if(!LT_O) was false, minutefuction() would not fulfill this requirement, and the combo would never start.

Code: Select all
combo LT_O
{                       
  set_val(L1, PRESS), set_val(O, PRESS); wait(ShortWait);// L1 && O Active for 250ms
  wait(ShortWait);// 250ms before next chord
  set_val(L1, PRESS), set_val(O, PRESS); wait(ShortWait);// L1 && O Active for 250ms
 // minutefunction();
}

Maybe you got confused from that last line in the combo. This is my fault I should have removed that line, to make it easier to follow.

This line does not contribute to the the combo repeating it self. Because it is only called once.
Again minutefunction(); needs to be called for a minute in order for the combo to start. The combo restarts, because if(!LT_O) remains true.

In order to stop this loop, its simple, you just have to to add another argument within the if(!LT_O) statement.

I never added anything because I did not know how you intended to have the combo start. or stop.

[quote="Liquidkhaos"]With a combo named BigHit, whay cant you call it like this:
Code: Select all
if(!BigHit)BigHit();

because BigHit is a combo, not a function for starters.


You don't want to be calling a combo every ms anyways, If
you want to use a combo as a timer, utilize the wait() functions within the combo,
That way the combo does not have to get called every ms.
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Wait() in an if block in a combo

Postby J2Kbr » Tue Nov 28, 2017 1:54 pm

Sillyasskid. as always, your explanation is precise and correct. thanks.
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Wait() in an if block in a combo

Postby Liquidkhaos » Sat Jan 06, 2018 5:17 pm

I meant to thank everyone for the support. :)
User avatar
Liquidkhaos
First Sergeant
First Sergeant
 
Posts: 61
Joined: Fri Sep 22, 2017 11:34 pm
Location: USA Tidewater Virginia


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 114 guests