Issues calling functions through serial.

Robin2:
...if all you want to do is control ON and OFF why not just send the single character 'N' for "on" and 'F' for "off"

but that isn't in the definition of what he is trying to do...

@Stew, you want to parse the message into a string and then look to see if it matches any pre-defined commands. You can do that using strcmp().

a functioning example using On or Off. Choose NewLine in the Serial Terminal

const size_t MAX_MESSAGE_LENGTH = 16;

int var[4];

void setup() 
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.println("let's go!");
}

void loop() 
{
  if(const char* newMessage = checkForNewMessage(Serial, '\n'))
  {
    Serial.print(F("Just Recieved:\t"));
    Serial.println(newMessage);
    if(strcmp(newMessage, "On") == 0)
    {
      gotOnMessage();
    }
    else if(strcmp(newMessage, "Off") == 0)
    {
      gotOffMessage();
    }
  }
}

void gotOnMessage()
{
  Serial.println(F("Got on message."));
  digitalWrite(13, HIGH);
}

void gotOffMessage()
{
  Serial.println(F("Got off message."));
  digitalWrite(13, LOW);
}

const char* checkForNewMessage(Stream& stream, const char endMarker)
{
  static char incomingMessage[MAX_MESSAGE_LENGTH] = "";
  static byte idx = 0;
  if(stream.available())
  {
    incomingMessage[idx] = stream.read();
    if(incomingMessage[idx] == endMarker)
    {
      incomingMessage[idx] = '\0';
      idx = 0;
      return incomingMessage;
    }
    else
    {
      idx++;
      if(idx > MAX_MESSAGE_LENGTH - 1)
      {
        //stream.print(F("{\"error\":\"message too long\"}\n"));  //you can send an error to sender here
        idx = 0;
        incomingMessage[idx] = '\0';
      }
    }
  }
  return nullptr;
}