Beginner—Serial RC Car—Forward and Backward

Hi
I am working on an RC car project where I enter a string of three commands into the serial monitor. It would be the direction, speed out of 255, and the duration.
forward, 150, 4000,
I am having a problem with the direction though. I am not sure how to have a reverse command. I already have it set up to go forward. I want to be able to enter either forward or reverse, then the speed, then duration. How would I set up a reverse?

#include <AFMotor.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

int rightLEDs = 9;
int leftLEDs = 10;

byte index = 0;
char inData[] = "forward, 12, 9876";
char *token = NULL;
byte count = 0;



void setup()
{
  pinMode(rightLEDs, OUTPUT);
  pinMode(leftLEDs, OUTPUT);
  digitalWrite(rightLEDs, HIGH);
  digitalWrite(leftLEDs, HIGH);
  Serial.begin(9600);
  Serial.println("RC Car Project Mark I connected.");
}

void loop()
{
  while(Serial.available() > 0)
  {
    token = strtok(inData, ",");
    while(token)
    {
      count++;
      
      if(count == 2)
      {
         int inputSpeed = atoi(token);
         motor1.setSpeed(inputSpeed);
         motor2.setSpeed(inputSpeed);
         motor3.setSpeed(inputSpeed);
         motor4.setSpeed(inputSpeed);
         Serial.print("Running forward at ");
         Serial.print(inputSpeed);
         Serial.print(" / 255 speed for ") ; 
      }
      
      else if(count == 3)
      {
        int duration = atoi(token);
        Serial.print(duration / 10);
        Serial.println(" seconds.");
        motor1.run(FORWARD);
        motor2.run(FORWARD);
        motor3.run(FORWARD);
        motor4.run(FORWARD);
        delay(duration);
        motor1.run(RELEASE);
        motor2.run(RELEASE);
        motor3.run(RELEASE);
        motor4.run(RELEASE);
      }
      
      token = strtok(NULL, ",");
    }
  }
}

Does anyone know how to do this?

The #include suggests that you're using an Adafruit motor shield, so you presumably already know that you need to use motor.run(BACKWARD); to reverse your motor. You're going to need to do something with the first token though to decide what to do. A series of if statements using strcmp would do it.

Since you're not reading the serial port, you can test this out by changing your test string. When you do start reading the port, be sure to avoid the serial.available trap: don't assume just because serial.available says that there is some data, that you have all of it - make sure you have the whole string - a terminating/separating character would help here.