Help with logic in saving tables

ok I moved the initialization if indexForFileNames outside (as gobal variable)

but still something is missing cause I only have 5 tables (and 6 sounds). It doesn’t save the first sound because of the >0 in the save part. But if I change that it will break the whole thing because of the fileNames[indexForFileNames-1]

void draw(){
  background(30);
  textSize(32);
  textAlign(CENTER, CENTER);
      
  if(runApp){
    text("Recording", width/2, height/2); 
    
    osc.amp(1);
    osc.play();

    int curTime = millis();
    int timeDiff = curTime - startTime;

    boolean saveThis = false; // tells the sketch to save  
    
    if (timeDiff < recTime) {      
      osc.freq(freqList[0]);
      indexForFileNames=0;
    } else if (timeDiff >= recTime && timeDiff < recTime*2) {
      if (indexForFileNames==0) {
        saveThis=true;
      }
      osc.freq(freqList[1]);
      indexForFileNames=1;
    } else if (timeDiff >= recTime*2 && timeDiff < recTime*3) {
      if (indexForFileNames==1) {
        saveThis=true;
      }
      osc.freq(freqList[2]);
      indexForFileNames=2;
    } else if (timeDiff >= recTime*3 && timeDiff < recTime*4) {
      if (indexForFileNames==2) {
        saveThis=true;
      }
      osc.freq(freqList[3]);
      indexForFileNames=3;
    } else if (timeDiff >= recTime*4 && timeDiff < recTime*5) {
      if (indexForFileNames==3) {
        saveThis=true;
      }
      osc.freq(freqList[4]);
      indexForFileNames=4;
    } else if (timeDiff >= recTime*5 && timeDiff < recTime*6) {
      if (indexForFileNames==4) {
        saveThis=true;
      }
      osc.freq(freqList[5]);
      indexForFileNames=5;
    } else
      startTime = millis();
    
    
    // save
    //println("RUN");
    if (saveThis && (indexForFileNames>0)) {
      saveTable(table, fileNames[indexForFileNames-1] + ".csv"); // using -1 here !!!!
      saveThis = false;
      println(indexForFileNames);

//need to move the following somewhere else
      //if(indexForFileNames == 5){
      //  runApp = false;
      //  exit();
      //}
        
    }
           
  }else
    text("Idle", width/2, height/2); 

}