Using multiple commands from X-CTU

Hi,

I am trying to control 2 motors with Arduino and X-CTU and I am using the following code:

#define motorInput1 4
#define motorPWM1 11
#define ledPin 13
#define motorPWM2 5
#define motorInput2 2

void setup() 
{
pinMode(ledPin, OUTPUT);
pinMode(motorInput1, OUTPUT);
pinMode(motorInput2, OUTPUT);
Serial.begin(9600);
}
void loop()
{
  if(Serial.available() > 0){
   byte val = Serial.read();
   if (val=='F') {
  digitalWrite(motorInput1, HIGH);  
  analogWrite(motorPWM1,220);  
  digitalWrite(motorInput2, HIGH);   
  analogWrite(motorPWM2,220);
  }
  if (val=='B') {
  digitalWrite(motorInput1, LOW);   
  analogWrite(motorPWM1,220);
  digitalWrite(motorInput2, LOW);   
  analogWrite(motorPWM2,220);
  }
   if (val=='R') {
  digitalWrite(motorInput1, LOW);   
  analogWrite(motorPWM1,100);
  digitalWrite(motorInput2, HIGH);   
  analogWrite(motorPWM2,100);
  }
  if (val=='L') {
  digitalWrite(motorInput1, HIGH);  
  analogWrite(motorPWM1,100);
  digitalWrite(motorInput2, LOW);   
  analogWrite(motorPWM2,100);
  }
  }
}

I am trying to let the user change the speed of the motors and additionally I am trying to write this code in a more practical way.

The problem is as soon as i send a byte of information on X-CTU it is processed in Arduino. I mean if I press "L" in the terminal. The motors start to work and I can't enter a value for PWM. I thought a way to build an array and make Arduino use the values in this array. However I can't figure out a way to fill the array if I use a for loop it just fills the array with the last command I entered. So how can I make it wait for the next command.

I can use your advices aswell on building a more practical code.
In general I am trying to let the user define the state of the movement in 8 directions (like forward backward right left...etc) and I want to let the user change the speed of the motors.

Thanks for the help already and sorry for my bad english.

Solved this actually with the following code

void setup(){
Serial.begin(9600);
}
void GetString(char *buf, int bufsize) //Get the command from the serial port
{

 int i;
 for (i=0; i<bufsize - 1; ++i) //start feeding the buf variable
 {
   while (Serial.available() == 0); // wait for character to arrive
   buf[i] = Serial.read(); //read data into buf
   if (buf[i] == '\0'  ) // is it the terminator byte?
     break;
 }
} 

void loop(){
char cmd[2]; //The first two bytes of the serial buffer
 char param[4]; //The last three bytes of the serial buffer
 char buffer[5];  //The whole buffer
 GetString(buffer, sizeof(buffer)); //capture the command from the serial port
 cmd[0] = buffer[0]; 
 cmd[1] = '\0'; //force a terminator byte
 param[0] = buffer[1];
 param[1] = buffer[2];
 param[2] = buffer[3];
 param[3] = '\0'; //force a terminator byte
if (strncmp(buffer, "F", 1)== 0 ) //Left Forward
 {
   Serial.print("Forward ");
   Serial.print(param);
 }

   }

thanks to this post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227279342