a function-definition is not allowed here before '{' token

hey everybody,

i am getting this error : a function-definition is not allowed here before '{' token

i have no clue what to do about this.

the very first line of the code is where i am getting this error.

i didnt paste my whole code, as it is to long. i also checked everything, and i have the same amount of "{" as "}".

can anyone help me out? thanks!

void printLastMovs(){
    if (mn > 1) {
      Serial.print(mn - 1, 0);
    }
    else {
      Serial.print("chess by sander");
    }
  }

void setup() {
  Serial.begin(9600);
  Serial.println("chess by sander");

  lastH[0] = 0;


  // playSerialMode();                  /* Debug mode using Serial Monitor */
}

void loop() {
  int r;

  // Print last movements
  printLastMovs();

  // Take move from human
  x1 = x2 = y1 = y2 = -1;
  takeMove();

  Serial.print("thinking");                       /* Turn for ARDUINO */

  K = *c - 16 * c[1] + 799, L = c[2] - 16 * c[3] + 799; /* parse entered move */
  N = 0;
  T = 0x3F;                                 /* T=Computer Play strength */
  // bkp();                                    /* Save the board just in case */
  r = D(-I, I, Q, O, 1, 3);                 /* Check & do the human movement */
  if ( !(r > -I + 1) ) {
    Serial.print("Lose ");
    gameOver();
  }
  if (k == 0x10) {                          /* The flag turn must change to 0x08 */
    oneNote(NOTE_F4, 8);
    oneNote(NOTE_C4, 8);
    oneNote(NOTE_C4, 8);
    Serial.print("     ");
    return;
  }

  strcpy(lastH, c);                        /* Valid human movement */

  mn++;                                     /* Next move */
  searchDataBase();                         /* Search in database */
  if (c[0]) {                               /* Movement found */

    Serial.print(c);
    Serial.print(" *");
    K = *c - 16 * c[1] + 799, L = c[2] - 16 * c[3] + 799; /* parse move found */
    N = 0;
    T = 0x3F;                             /* T=Computer Play strength */
    r = D(-I, I, Q, O, 1, 3);             /* Check & do*/
    if ( !(r > -I + 1) ) gameOver();
    if (k == 0x08) {
      Serial.print("ERR DB");
      Serial.print("game over");
      gameOver();
    }

    strcpy(lastM, c);                     /* Valid ARDUINO movement */
    delay(1000);
    return;
  }

  K = I;
  N = 0;
  T = 0x3F;                                 /* T=Computer Play strength */
  r = D(-I, I, Q, O, 1, 3);                 /* Think & do*/
  if ( !(r > -I + 1) ) {
    Serial.print("Lose*");
    gameOver();
  }

  if (k == 0x08) {                          /* Some times the algorithm do not */
    Serial.print("ERR 3 ");                  /* the turn flag */
    gameOver();                           /* 1. b1c3  c7c5?       2. f2f4? */
  }
  strcpy(lastM, c);                         /* Valid ARDUINO movement */
  strcpy(c, "a1a1");                        /* Execute a invalid move to check score again */
  r = D(-I, I, Q, O, 1, 3);
  if ( !(r > -I + 1) ) {
    Serial.print(lastM);
    Serial.print(" ");
    gameOver();
  }
  if (k == 0x08) {                          /* execute the move and do not change */
    Serial.print("ERR 3 ");                  /* the turn flag */
    gameOver();                           /* 1. b1c3  c7c5?       2. f2f4? */
  }

}

I get A LOT or errors when I try that code. But non is the one you give. So I'm guessing you're not posting all the code. At least you didn't post the complete error.

Bonus tip, short variable names, especially single letter variable names, are asking for trouble! Variables are there to help you, give them useful names :slight_smile:

If you don't post the entire error message, we don't know where (file, line) to start looking. If you don't post the whole code, we can't verify the code to find the location of the error.

Does the error show on the printLastMovs line? What is above the printLastMovs function definition line? I would say that the error may be there in the code that you did not post.

Write a small example code that gives the error.

You're right that the usual cause for this error is a mismatched set of curly braces. But there are some tricky ways you might end up with a mismatch even if you've counted the braces.

For example, you could have a trailing brace at the end that was actually outside the executable block. Or you may have a comment that includes a line with a brace.

There's really no way to tell where you've got them misaligned without going through the code.