Help with Arrays

Gtuner Pro general support. Operation, questions, updates, feature request.

Help with Arrays

Postby LudusMachinae » Fri Apr 26, 2019 8:22 pm

I'm trying to make a program that will save angles from the left stick (up to 3 of them) and then spam those angles (either one, two or three of them) when A is pressed. (without going too in depth its a method of escaping combos in smash ultimate so its good to practice counterplay but the in-game training mode is trash) anyway, it seems to be only saving the angles once and not letting me change them again by pressing Y unless I reset the script with the button on the titan. do arrays only let you change them once or have I done something wrong?

Code: Select all
// SDI program
int trainMode;
int activate;
int angleArray[5];
int angleNum;
 
init {
    trainMode = 1;
    activate = 0;
    angleNum = 1;
}
 
main {
//if Y is pressed, the scripts reads left stick and saves it to the array, up to 3 of them
 
    if(event_press (SWITCH_Y)){
        if(angleNum == 1) {
            angleNum = 2
            angleArray[0]=get_val(SWITCH_LX)
            angleArray[1]=get_val(SWITCH_LY)
            }
        if (angleNum==2) {
            angleNum = 3           
            angleArray[2]=get_val(SWITCH_LX)
            angleArray[3]=get_val(SWITCH_LY)
            }
        if (angleNum==3){
            angleNum = 1
            angleArray[4]=get_val(SWITCH_LX)
            angleArray[5]=get_val(SWITCH_LY)
            }
        }
    //when up or down is pressed, combo mode changes
    if (event_press (SWITCH_UP)) {
        if(trainMode==3){
            trainMode = 1
        }
        else{   
            trainMode = trainMode+1
        }
    }
    if (event_press (SWITCH_DOWN)) {
        if(trainMode==1) {
            trainMode = 3
        }
        else{   
            trainMode = trainMode-1
        }
    }
    //when A is pressed, Combo starts
    if (event_press (SWITCH_A)) {
        if (activate == 1) {
            activate=0
        }
        else{
            activate=1
        }
    }
    //when A is pressed, this part checks what DI mode is chosen and calls the combo
    if(activate==1){
        if(trainMode==1){
            combo_run(A)
        }
        if(trainMode==2){
            combo_run(B)
        }
        if(trainMode==3){
            combo_run(C)
        }
    }
}
 
combo A {
 // single angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, 0)
 set_val(SWITCH_LY, 0)
}
 
combo B {
// Dual angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
}
 
 combo C {
 //triple angel DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
 set_val(SWITCH_LX, angleArray[4])
 set_val(SWITCH_LY, angleArray[5])
 wait(30)
}
 
User avatar
LudusMachinae
Private First Class
Private First Class
 
Posts: 2
Joined: Fri Apr 26, 2019 8:03 pm

Re: Help with Arrays

Postby Scachi » Sat Apr 27, 2019 8:40 am

Your angleArray is of wrong size. It can only hold 5 values but you want it to store 6.
Array index starts with [0], and its end index is [size-1]
Code: Select all
int angleArray[6]; // 0,1,2,3,4,5 == 6 values


You are writing into all indices of angleArray at once with a single press of SWITCH_Y.
You can fix this by using "else if" to write at a pair on each press of SWITCH_Y.

Try if this is working for you:
Code: Select all
// SDI program
int trainMode;
int activate;
int angleArray[6];
int angleNum;
 
init {
    trainMode = 1;
    activate = 0;
    angleNum = 1;
}
 
main {
//if Y is pressed, the scripts reads left stick and saves it to the array, up to 3 of them
 
    if(event_press (SWITCH_Y)){
        if(angleNum == 1) {
            angleNum = 2
            angleArray[0]=get_val(SWITCH_LX)
            angleArray[1]=get_val(SWITCH_LY)
            }
        else if (angleNum==2) {
            angleNum = 3           
            angleArray[2]=get_val(SWITCH_LX)
            angleArray[3]=get_val(SWITCH_LY)
            }
        else if (angleNum==3){
            angleNum = 1
            angleArray[4]=get_val(SWITCH_LX)
            angleArray[5]=get_val(SWITCH_LY)
            }
        }
    //when up or down is pressed, combo mode changes
    if (event_press (SWITCH_UP)) {
        if(trainMode==3){
            trainMode = 1
        }
        else{   
            trainMode = trainMode+1
        }
    }
    if (event_press (SWITCH_DOWN)) {
        if(trainMode==1) {
            trainMode = 3
        }
        else{   
            trainMode = trainMode-1
        }
    }
    //when A is pressed, Combo starts
    if (event_press (SWITCH_A)) {
        if (activate == 1) {
            activate=0
        }
        else{
            activate=1
        }
    }
    //when A is pressed, this part checks what DI mode is chosen and calls the combo
    if(activate==1){
        if(trainMode==1){
            combo_run(A)
        }
        if(trainMode==2){
            combo_run(B)
        }
        if(trainMode==3){
            combo_run(C)
        }
    }
}
 
combo A {
 // single angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, 0)
 set_val(SWITCH_LY, 0)
}
 
combo B {
// Dual angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
}
 
 combo C {
 //triple angel DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
 set_val(SWITCH_LX, angleArray[4])
 set_val(SWITCH_LY, angleArray[5])
 wait(30)
}
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Help with Arrays

Postby LudusMachinae » Sun Apr 28, 2019 2:14 am

Scachi wrote:Your angleArray is of wrong size. It can only hold 5 values but you want it to store 6.
Array index starts with [0], and its end index is [size-1]
Code: Select all
int angleArray[6]; // 0,1,2,3,4,5 == 6 values


You are writing into all indices of angleArray at once with a single press of SWITCH_Y.
You can fix this by using "else if" to write at a pair on each press of SWITCH_Y.

Try if this is working for you:
Code: Select all
// SDI program
int trainMode;
int activate;
int angleArray[6];
int angleNum;
 
init {
    trainMode = 1;
    activate = 0;
    angleNum = 1;
}
 
main {
//if Y is pressed, the scripts reads left stick and saves it to the array, up to 3 of them
 
    if(event_press (SWITCH_Y)){
        if(angleNum == 1) {
            angleNum = 2
            angleArray[0]=get_val(SWITCH_LX)
            angleArray[1]=get_val(SWITCH_LY)
            }
        else if (angleNum==2) {
            angleNum = 3           
            angleArray[2]=get_val(SWITCH_LX)
            angleArray[3]=get_val(SWITCH_LY)
            }
        else if (angleNum==3){
            angleNum = 1
            angleArray[4]=get_val(SWITCH_LX)
            angleArray[5]=get_val(SWITCH_LY)
            }
        }
    //when up or down is pressed, combo mode changes
    if (event_press (SWITCH_UP)) {
        if(trainMode==3){
            trainMode = 1
        }
        else{   
            trainMode = trainMode+1
        }
    }
    if (event_press (SWITCH_DOWN)) {
        if(trainMode==1) {
            trainMode = 3
        }
        else{   
            trainMode = trainMode-1
        }
    }
    //when A is pressed, Combo starts
    if (event_press (SWITCH_A)) {
        if (activate == 1) {
            activate=0
        }
        else{
            activate=1
        }
    }
    //when A is pressed, this part checks what DI mode is chosen and calls the combo
    if(activate==1){
        if(trainMode==1){
            combo_run(A)
        }
        if(trainMode==2){
            combo_run(B)
        }
        if(trainMode==3){
            combo_run(C)
        }
    }
}
 
combo A {
 // single angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, 0)
 set_val(SWITCH_LY, 0)
}
 
combo B {
// Dual angle DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
}
 
 combo C {
 //triple angel DI
 set_val(SWITCH_LX, angleArray[0])
 set_val(SWITCH_LY, angleArray[1])
 wait(30)
 set_val(SWITCH_LX, angleArray[2])
 set_val(SWITCH_LY, angleArray[3])
 wait(30)
 set_val(SWITCH_LX, angleArray[4])
 set_val(SWITCH_LY, angleArray[5])
 wait(30)
}
 


THANKS! looks like this worked. totally spaced that it was cycling all the angles in one pass of Y. time to add more to the program and probably break it :P
User avatar
LudusMachinae
Private First Class
Private First Class
 
Posts: 2
Joined: Fri Apr 26, 2019 8:03 pm


Return to Gtuner Pro Support

Who is online

Users browsing this forum: No registered users and 52 guests