Error: variable not defined in scope?

So i have this code to read a char from serial:

while(!Serial.available())
char character = Serial.read();
if (character == "1") startup(1);
if (character == "2") startup(2);

but it is giving me this error every time i run it:

SerialDisplay:29: error: 'character' was not declared in this scope
SerialDisplay:30: error: 'character' was not declared in this scope

i don't get it. i declared the variable one line ago and it is not finding it?

Correct your indentation, and you'll see the problem

while(!Serial.available())
char character = Serial.read();
if (character == "1") startup(1);
if (character == "2") startup(2);

oh silly me. i wasnt meaning for those things to be inside the while. i simply put a {} after the while and that solved it. thanks.

char character = Serial.read();
if (character == "1") startup(1);
if (character == "2") startup(2);

The one character is never going to match a string literal. The one character might, or might not, match a single character ('1' or '2').

If there is more than one character available, you code will only consider the last one.

Anyway, rather than blocking with:

  while (Serial.available () == 0) {}  // available returns an integer, test against zero...
  char c = Serial.read () ;
  ...

It is usually much more useful to poll for input:

  if (Serial.available () > 0)
  {
    char c = Serial.read () ;
    ....
  }
  // other stuff here isn't blocked due to busy-waiting

There is also the SerialEvent mechanism.

Also, your code:

  while(!Serial.available()) {
  }
  char character = Serial.read();
  if (character == "1") 
     startup(1);
  if (character == "2") 
    startup(2);

can be improved a little. For example, if you do get a '1', you call startup() and then immediately check to see if it is a '2', which it can't be. A switch statement can prevent these unnecessary checks:

  // ...
  char character = Serial.read();
  switch (character) {
     case 1:
         startup(1);
         break;
     case 2:
         startup(1);
         break;
     default:
         Serial.println("We shouldn't be here.");
         break;
  }

Another option that is not as self-documenting would be:

     char character = Serial.read();
     int index = character - '0';  // e.g., if character = '7', then (ASCII codes) 55 - 48 = 7
     startup(index);

This would work for the two examples you've shown that use numeric indexes. Since all of the code wasn't posted, I don't know if non-numeric codes need to be processed.

I think you need some single quotes around your cases.

I think you need some single quotes around your cases.

Yep, you're right. It would be better to do away with the switch all together as suggested in the last code block, if possible.