Can someone make this script loop automatically? (Toggle)

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

Can someone make this script loop automatically? (Toggle)

Postby LegendHimself » Sat Jan 26, 2019 10:22 am

The macro file is on a Micro SD, running perfectly as is. I just want it to toggle on and off loop with the button press instead of having to tap it every time.

Code: Select all
 
main {
    if(event_active(BUTTON_13)) { // Run the Macro once.
            macro_run("Reset.gmk");
    }
}
 
User avatar
LegendHimself
Private First Class
Private First Class
 
Posts: 3
Joined: Sat Jan 26, 2019 10:07 am

Re: Can someone make this script loop automatically? (Toggle

Postby Scachi » Sat Jan 26, 2019 12:31 pm

Code: Select all
bool Toggle=FALSE;
 
main {
  if(event_active(BUTTON_13)) Toggle=!Toggle;
 
  if (Toggle) macro_run("Reset.gmk");
}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Can someone make this script loop automatically? (Toggle

Postby LegendHimself » Sat Jan 26, 2019 12:48 pm

Thanks, I appreciate it. Is there a way to set a wait timer so it loops every x amount of seconds?
User avatar
LegendHimself
Private First Class
Private First Class
 
Posts: 3
Joined: Sat Jan 26, 2019 10:07 am

Re: Can someone make this script loop automatically? (Toggle

Postby J2Kbr » Wed Jan 30, 2019 2:03 pm

LegendHimself wrote:Thanks, I appreciate it. Is there a way to set a wait timer so it loops every x amount of seconds?

This will do:
Code: Select all
bool Toggle;
int32 timer;
 
main {
    if(event_active(BUTTON_13)) {
        Toggle = !Toggle;
        timer = 0;
    }
 
    if(Toggle && macro_time() < 0) {
        if(timer > 0) {
            timer -= elapsed_time();
        } else {
            macro_run("Reset.gmk");
            timer = 5000; // Time to wait
        }
    }
}
 
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: Can someone make this script loop automatically? (Toggle

Postby LegendHimself » Wed Jan 30, 2019 3:13 pm

Thanks for your help as well J2Kbr
User avatar
LegendHimself
Private First Class
Private First Class
 
Posts: 3
Joined: Sat Jan 26, 2019 10:07 am

Re: Can someone make this script loop automatically? (Toggle

Postby rivox1 » Sat Apr 27, 2019 11:02 pm

I'm very interested in this, thank you for sharing and everyone who participated.

How would you go about looping the macro a set amount of TIMES instead of using a timer.

Thank you
User avatar
rivox1
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Sun Sep 03, 2017 6:07 pm

Re: Can someone make this script loop automatically? (Toggle

Postby J2Kbr » Mon Apr 29, 2019 10:49 am

rivox1 wrote:How would you go about looping the macro a set amount of TIMES instead of using a timer.

Example of how execute the macro a certain amount of TIMES:
Code: Select all
#define TIMES   5
 
bool Toggle;
int32 counter;
 
main {
    if(event_active(BUTTON_13)) {
        Toggle = !Toggle;
        counter = 0;
    }
 
    if(Toggle && macro_time() < 0) {
        if(counter < TIMES) {
            macro_run("Reset.gmk");
            counter++;
        }
    }
}
 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 142 guests