send array of integers via xBee s1

float ping()//questa funzione misura la distanza attraverso il sensore a ultrasuoni HC-SR04 viene usata sia durante la marcia sia durante la scelta della direzione da prendere
{
  long durata,distanza; //dichiarazione variabili per la funzione
  distanza=0.034*durata/2; 
  return distanza;
}

distanza is NOT a float. Make the return type and the value returned match.

  servo1.write(40); //la prima direzione è sinistra a 45°

40 does not equal 45.

long distL,distR;
  distL=ping(); //viene campionata la distanza a destra

ping() currently returns a float. Why are you storing it in a long?

  servo1.write(130); //la seconda è fatta a destra a 135°

130 does not equal 135.

Get rid of incorrect comments, or fix them.

  if(distR<40&&distL<40)

Use the space key!

    Serial3.flush();

A sure sign that you don't understand serial communication.

Having just the receiver code is not enough. We need to see what the sender is sending. You seem to expect to read an integer value calling Serial3.read(). You will read one byte/character using SerialN.read().

  if(Serial3.available()>4)
  {
    Serial.print("incomingdata");
    while(Serial3.read()!=char(253)){Serial.read();}
    for(int i=0;i<4;i++)
    {
      serialcom[i]=Serial3.read();
      //Serial.print(Serial3.read());
    }

If there are 5 or more characters to read, read and throw away some number of them. Then, read 4 more. That won't work. You need to read and throw away characters until the 253 arrives, then wait until there are 4 more characters/bytes. Then, read the bytes/characters.