Track Macro Completion / Iteration - Questions

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

Track Macro Completion / Iteration - Questions

Postby USER102 » Tue Dec 11, 2018 9:36 pm

Thanks in advance.

• What is the best way to track the completion of a macro?

• Should I place macro_run() inside a while statement to determine how many times it has run or to determine when it has completed its course?

Code: Select all
if(something cool){ // will this play the macro 10 times?
   uint8 i=0;
   while(i<10){
      macro_run(awesome_macro);
      i++;
   }
 


• Does macro_run need to be in a combo to even run more than once?

• If a task comes after macro_run() in the same statement does it wait until the macro is compete before moving to the next task?

Code: Select all
if(something cool){ // will this play the macro then stop the combo once complete?
     macro_run(awesome_macro);
     combo_stop(cool_combo);
   }
 
User avatar
USER102
Private First Class
Private First Class
 
Posts: 2
Joined: Tue Dec 11, 2018 9:13 pm

Re: Track Macro Completion / Iteration - Questions

Postby USER101 » Wed Dec 12, 2018 4:11 am

How do you tell when a macro is complete?
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Track Macro Completion / Iteration - Questions

Postby Scachi » Wed Dec 12, 2018 4:56 am

Jesscorp wrote:How do you tell when a macro is complete?

When macro_time() changes from returning values > -1 to -1
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Track Macro Completion / Iteration - Questions

Postby Sillyasskid » Wed Dec 12, 2018 5:26 am

USER101 wrote:Thanks in advance.

• What is the best way to track the completion of a macro?

Here is one method of tracking a macro repetition.
Code: Select all
bool toggle = TRUE;
int loop;
 
main {
 
  if(toggle == TRUE){
  //As long as toggle is true, the macro will loop.
    macro_run("macro1.gmk");
 
  //The macro has started when macro_time == 0.
    if(macro_time() == 0) printf("loop %d", ++loop);
 
  //after 10 loops, toggle becomes false.
    if(loop==10) toggle = FALSE;
  }
}


USER101 wrote:• Should I place macro_run() inside a while statement to determine how many times it has run or to determine when it has completed its course?

That's a definite a no. A while loop implemented like this, will cause your T2 to automatically timeout. While loops need to be used with caution.
USER101 wrote:• Does macro_run need to be in a combo to even run more than once?

Nope. See above example.
USER101 wrote:• If a task comes after macro_run() in the same statement does it wait until the macro is compete before moving to the next task?

No What will happen is, the macro will run, and the combo will stop. At the same time. The combo won't wait until the macro is finished before its instructed to stop.
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: Track Macro Completion / Iteration - Questions

Postby USER101 » Wed Dec 12, 2018 9:02 am

I used your example and alive becomes TRUE as soon example.gmk starts, is there a way to change the condition upon completion of the macro?

Code: Select all
           bool alive = FALSE;        
           main {
                macro_run("example.gmk");
                if(macro_time() == -1) { // After macro runs it should change the conditions?.
                time_counter = 0;
                alive = TRUE;
                }
                }
User avatar
USER101
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Mon Dec 03, 2018 5:45 pm

Re: Track Macro Completion / Iteration - Questions

Postby Scachi » Wed Dec 12, 2018 9:06 am

Jesscorp wrote:I used your example and alive becomes TRUE as soon example.gmk starts, is there a way to change the condition upon completion of the macro?

Code: Select all
           bool alive = FALSE;        
           main {
                macro_run("example.gmk");
                if(macro_time() == -1) { // After macro runs it should change the conditions?.
                time_counter = 0;
                alive = TRUE;
                }
                }

If it can't start the macro/find the file it will also return -1

If the file is accessible your code would never set alive to TRUE as you are restarting it all this time with your macro_run command.
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 119 guests