Need help with loop for amount of times

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

Need help with loop for amount of times

Postby A1rookie » Sun Nov 20, 2022 4:18 pm

Script should work like this:
When pressing L3, run combo1 OR combo2 . Repeat this for 5-8 times, then stop.
So also randomly choose between the combos on every repeat.

for example if random repeat amount was 5, Output should look like:
Combo1
Combo1
Combo2
Combo1
Combo2

i tried for hours, sorry, have only little coding experience. at the moment both combos are triggered at the same time , and the number of repeats also doesnt seem to work.
would be perfect if your solution was scalable for adding more combos to this.

Thanks!

Code: Select all
#define irand(a,b) (((int)(rand() * (fix32)(b+1 - a))) + a)
#include <PS4.gph>
int random,limit, count;
bool loop;
 
main {
if (event_active(PS4_L3)) {
    count=0;
    limit=irand(5,8);
    loop=TRUE;}
 
if (count>limit) {loop=FALSE;}
 
//section A
if (loop) {
        random=irand(1,2);
        if (random==1)combo_run(combo1);
        if (random==2)combo_run(combo2);}
 
}
 
combo combo1 {
    set_val(PS4_R2,100);
    wait(100);
    set_val(PS4_R2, 0);
    wait(100);
    set_val(PS4_R2,100);
    wait(100);
    ++count;}
 
combo combo2 {
    set_val(PS4_L2,100);
    wait(100);
    set_val(PS4_L2, 0);
    wait(100);
    set_val(PS4_L2,100);
    wait(100);
    ++count;}
User avatar
A1rookie
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Mon Sep 10, 2018 5:26 pm

Re: Need help with loop for amount of times

Postby Tahsin » Sun Jan 15, 2023 9:57 pm

Hi i'm new to T2 coding i've tested it works fine just coppy it :smile0201:

Code: Select all
#define irand(a,b) (((int)(rand() * (fix32)(b+1 - a))) + a)
#include <PS4.gph>
int random,limit, count;
bool loop;
 
main {
if (get_actual(BUTTON_9)) {
    count=0;
    limit=5;
    loop=TRUE;}
 
if (count==4) {loop=FALSE;}
 
//section A
if (loop) {
        random=irand(0,5);
        if (random==1)combo_run(combo1);
        if (random==2)combo_run(combo2);
 
    }
 
}
 
combo combo1 {
    set_val(BUTTON_5,100);
    wait(100);
    set_val(BUTTON_5, 0);
    wait(100);
    count++;
     printf("R2 Pressed");
 
    }
 
combo combo2 {
    set_val(BUTTON_8,100);
    wait(100);
    set_val(BUTTON_8, 0);
    wait(100);
    count++;
    printf("L2 Pressed");
    }
 
User avatar
Tahsin
Sergeant Major
Sergeant Major
 
Posts: 100
Joined: Wed May 15, 2019 7:57 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: joey44001 and 83 guests