Not able to pass array in function, getting not declared in scope.

I’ve tried passing them with and without and () and &. I keep getting “exit status 1
‘onRelays’ was not declared in this scope” pointing at SetRelays(onRelays,offRelays);

Not sure exactly how to achieve this do they need to be declared globally or public or something? I’d rather not because I need to make several other functions using those same arrays but of different sizes.

//List of relays at bottom
int relays[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}; //Skip 0 [1] threw [19] relays 1-19
int batteryStatus[] = {0,0,0,0,0,0,0,0,0,0,0}; //Skips 0, status 0 = needs charging, 1 = charging, 2 = charged ready to discharge, 3 = discharging 12v, 4 = discharging 24v

void setup() {
  for(int i = 1;i<19;i++){
    pinMode(relays[i],OUTPUT);
    digitalWrite(relays[i],LOW); //Inilitilizes all relays low
  }
}

void loop() {

}

void ChargeBattery(int batteryToCharge){
  if (batteryToCharge < 6){
    int onRelays[] = {0,0};
    int offRelays[] = {0,0};
  } 
  else if (batteryToCharge < 11){
    int onRelays[] = {0,0};
    int offRelays[] = {0,0};
    }
  batteryToCharge = 14 - batteryToCharge;
  SetRelays(onRelays,offRelays);
  }
void ZeroRelays(){
  for(int i=1;i<20;i++){
    digitalWrite(relays[i],LOW);
  }
  return;
}
void SetRelays(int on[], int off[]){
  for(int i = 0; i<sizeof(off) - 1; i++){
    digitalWrite(off[i],LOW);
  }
  delay(50);
  for(int i = 0; i<sizeof(on) - 1; i++){
    digitalWrite(on[i],HIGH);
  }
  return;
}
{
    int onRelays[] = {0,0};
    int offRelays[] = {0,0};
    }

The scope of these arrays is very, very limited.

And why skip 0????

GrooveFlotilla:

{

int onRelays = {0,0};
    int offRelays = {0,0};
    }


The scope of these arrays is very, very limited.

Ah sorry, I'm used to python where lists are a lot easier to use. So if I declare the on and off arrays at the top of the function wouldn't it need a predefined size? Also I couldn't adjust them by doing something as easy as = {1,2,...etc} would I? They will be fairly lengthy with around 10 entries each and I'd hate to do [1] = 3 [2] = 8 and so forth. Is there an easy way for this?

septillion:
And why skip 0????

We are using a relay board that is numbered 1-16 so someone else working on the project wanted consistency between the two to avoid setting up an incorrect pair which could cause a fault.

dansoftcore:
Ah sorry, I'm used to python where lists are a lot easier to use. So if I declare the on and off arrays at the top of the function wouldn't it need a predefined size? Also I couldn't adjust them by doing something as easy as = {1,2,...etc} would I? They will be fairly lengthy with around 10 entries each and I'd hate to do [1] = 3 [2] = 8 and so forth. Is there an easy way for this?
We are using a relay board that is numbered 1-16 so someone else working on the project wanted consistency between the two to avoid setting up an incorrect pair which could cause a fault.

C/C++ uses static scoping while python uses dynamic.
What it means is that every declared inside { .. } only exists inside those braces bracket.
(Well this is one exception with "static" keyword)

arduino_new:
C/C++ uses static scoping while python uses dynamic.
What it means is that every declared inside { … } only exists inside those braces bracket.
(Well this is one exception with “static” keyword)

Thank you for clarifying that, and I got around this by just calling the method that referenced them in each of the two cases like such, in case anyone cares.

Also one last question, is the return required in arduino for void functions?

void ChargeBattery(int batteryToCharge){
  if (batteryToCharge < 6){
    int onRelays[] = {3, 19, 14-batteryToCharge};
    int offRelays[] = {14,15,16,17,2,1};
    SetRelays(offRelays,offRelays);
  } 
  else if (batteryToCharge < 11){
    int onRelays[] = {2, 19, 14-batteryToCharge};
    int offRelays[] = {14,15,16,18,3,1};
    SetRelays(offRelays,offRelays);
    }  
  batteryStatus[batteryToCharge] = 1;
  return;
}

dansoftcore:
Thank you for clarifying that, and I got around this by just calling the method that referenced them in each of the two cases like such, in case anyone cares.

Also one last question, is the return required in arduino for void functions?

void ChargeBattery(int batteryToCharge){

if (batteryToCharge < 6){
    int onRelays = {3, 19, 14-batteryToCharge};
    int offRelays = {14,15,16,17,2,1};
    SetRelays(offRelays,offRelays);
  }
  else if (batteryToCharge < 11){
    int onRelays = {2, 19, 14-batteryToCharge};
    int offRelays = {14,15,16,18,3,1};
    SetRelays(offRelays,offRelays);
    } 
  batteryStatus[batteryToCharge] = 1;
  return;
}

I am still not convinced this function is the best as far are efficiency and usage of language.
I would prefer both arrays to be declared as local to the function and defined in if() construct.

void ChargeBattery(int batteryToCharge){
 int onRelays[size] = {};
    int offRelays[size] = {};
 if (batteryToCharge <6 )
    onRelays[] = {3, 19, 14-batteryToCharge};
    offRelays[] = {14,15,16,17,2,1};
   
  } 
  else {   // assuming there is only one "else not < 6" 
    onRelays[] = {2, 19, 14-batteryToCharge};
    offRelays[] = {14,15,16,18,3,1};
    
    }  
  SetRelays(offRelays,offRelays);         //I am sure this is a typo 
  batteryStatus[batteryToCharge] = 1;
  return;
}

No - “return” on void function is not necessary.

I would like to see the SetRelays function code, if possible.