Error: invalid types 'int[int]' for array subscript I am trying to get an Arduino to work with some Adafruit Motor shields. 
Everything seemed to work fine, but when I tried to create a function, I get the error in the subject. As far as I can tell, everything was declared properly (the array is initialized and is indexed elsewhere with without issue). Only the function seems to cause an issue.

Would anyone have a guess at what's wrong?

    //////// Imports
    #include &lt;Wire.h&gt;
    #include &lt;Adafruit_MotorShield.h&gt;
    #include "utility/Adafruit_PWMServoDriver.h"

    ////////My globals. Times are in milliseconds
    unsigned long currentTime = 0;
    unsigned long elapsedTime = 0;
    unsigned long startTime = 0;
    byte currentMotor = 1;
    byte currentShield = 1;
    byte motorRunning = 0;

    //// Settings

    // How many seconds between motors
    unsigned long endTime = 4000;

    // How many shields and motors per shield
    const int nShields = 1;
    const int nMotorsPerShield = 3;

    /////////MicroManager globals
    unsigned int version_ = 2;
    const unsigned long timeOut_ = 1000;
    byte currentPattern_ = 0;
    unsigned long time;

    /////////Adafruit globals
    Adafruit_MotorShield afms[nShields];
    Adafruit_DCMotor *motor[nShields][nMotorsPerShield];

    ////////////Setup
    void setup() {
      Serial.begin(57600);

      unsigned char address = 96;

      for (int i = 0; i &lt; nShields; i++) {
        afms[i] = Adafruit_MotorShield(address);
        address = ++address;
        afms[i].begin();
      }

      for (int i = 0; i &lt; nShields; i++) {
        for (int j = 0; j &lt; nMotorsPerShield; j++) {
          motor[i][j] = afms[i].getMotor(j + 1);
          motor[i][j]-&gt;setSpeed(255);
        }
      }

      pinMode(13, OUTPUT);
    }

    ////////////////////Main
    void loop() {
      currentTime = millis();
      elapsedTime = currentTime - startTime;

      if (elapsedTime &gt; endTime) {
        startTime = currentTime;
        currentMotor = currentMotor + 1;
        if (currentMotor &gt; nMotorsPerShield) {
          currentMotor = 1;
        }
      }

      if (Serial.available() &gt; 0) {
        int inByte = Serial.read();

        switch (inByte) {
          case 1:
            if (waitForSerial(timeOut_)) {
              currentPattern_ = Serial.read();
              if (currentPattern_ == 0) {
                for (int i = 0; i &lt; nShields; i++) {
                  for (int j = 0; j &lt; nMotorsPerShield; j++) {
                    motor[1][j]-&gt;run(RELEASE);
                  }
                }
              }
              else {
                switchMotor();
              }
              Serial.write( byte(1));
              digitalWrite(13, HIGH);
            }
            break;

          case 30:
            Serial.println("MM-Ard");
            break;

          case 31:
            Serial.println(version_);
            break;
        }
      }

      digitalWrite(13, LOW);
    }


    ////////////////Function definitions

    bool waitForSerial(unsigned long timeOut)
    {
      unsigned long starTime = millis();
      while (Serial.available() == 0 &amp;&amp; (millis() - starTime &lt; timeOut) ) {}
      if (Serial.available() &gt; 0)
        return true;
      return false;
    }

    void switchMotor()
    {
      int shield = currentShield - 1;
      int motor = currentMotor - 1;
      for (int i = 0; i &lt; nShields; i++) {
        for (int j = 0; j &lt; nMotorsPerShield; j++) {
          if (i == shield &amp;&amp; j == motor)
            motor[i][j]-&gt;run(FORWARD);
          else
            motor[i][j]-&gt;run(RELEASE);
        }
      }
    }
Take a close look at this line:

motor[1][j]-&gt;run(RELEASE);


Looks like it should be:

motor[i][j]-&gt;run(RELEASE);


Otherwise it is an illegal index (as there is only one shield). 

The next error is in the function switchMotor(). Again, have a close look at the definition of "motor". There is a local variable with that name but you want to also access the global array with the same name.

void switchMotor()
{
  int shield = currentShield - 1;
  int motor = currentMotor - 1;
      ^
  for (int i = 0; i &lt; nShields; i++) {
    for (int j = 0; j &lt; nMotorsPerShield; j++) {
      if (i == shield &amp;&amp; j == motor)
        motor[i][j]-&gt;run(FORWARD);
        ^
      else
        motor[i][j]-&gt;run(RELEASE);
    }
  }
}


My guess is that this is where the compiler give you the error message!

Cheers!