How to solve "a function-definition is not allowed here before '{' token"

Hello, I'm just starting with Arduino and was coding a way to make a stoplight that relies on a sensor and a timer. Basically, the lights will change depending on whether an object passes through the sensor before the timer is up. This is the code:

/*

*/

unsigned long currentTime;
unsigned long loopTime;
int g1 = 10;                // the pin that the LED is atteched to
int y1 = 9;
int r1 = 8;
int g2 = 13;
int y2 = 12;
int r2 = 11;
int g3 = 7;
int y3 = 6;
int r3 = 5;
int sensor = 2;              // the pin that the sensor is attached to
int state = LOW;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)

void setup() {
  currentTime = millis();
  loopTime = currentTime;
  pinMode(r1, OUTPUT);      // initalize LED as an output
  pinMode(r2, OUTPUT);
  pinMode(r3, OUTPUT);
  pinMode(y1, OUTPUT);
  pinMode(y2, OUTPUT);
  pinMode(y3, OUTPUT);
  pinMode(g1, OUTPUT);
  pinMode(g2, OUTPUT);
  pinMode(g3, OUTPUT);
  digitalWrite(g2, HIGH);
  digitalWrite(g3, HIGH);
  digitalWrite(r1, HIGH);
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(9600);        // initialize serial
  // initialize serial

  void loop() {
    if (digitalRead(sensor) == HIGH) // Switch is closed to start LED timer
    {
      currentTime = millis();
      if (digitalRead(sensor) == HIGH)
      {
        if ( mils - wasmils >= 1000 );
        {
          seconds ++;
          wasmils = mils;
          digitalWrite(g1, HIGH);
          digitalWrite(r2, HIGH);
          digitalWrite(r3, HIGH);
          digitalWrite(g2, LOW);
          digitalWrite(g3, LOW);
          digitalWrite(r1, LOW);
        }
      }
      else
        delay(10000);
      digitalWrite(g1, HIGH);
      digitalWrite(r2, HIGH);
      digitalWrite(r3, HIGH);
      digitalWrite(g2, LOW);
      digitalWrite(g3, LOW);
      digitalWrite(r1, LOW);
    }
  }

Whenever I try to verify it, I always get the error "a function-definition is not allowed here before '{' token". Can anyone tell me how to fix the error? Thank you in advance :)))))

(deleted)

:00000000 I see. Thank you for the reply :slight_smile:

A very helpful troubleshooting tool is the Auto Format feature (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor). If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace.

Another useful feature of the Arduino IDE/Arduino Web Editor is that when you place the cursor next to one bracket, it puts a box around the matching bracket. In the Arduino IDE, if the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.