Problem with a function

hello, I made this simple function:

boolean afuera(int px, int py, int dir) {
switch (dir) {
case 1:
afuera = (px - 1) < 0 || (py + 1) > 7;
break;
case 2:
afuera = (px + 1) > 7 || (py + 1) > 7;
break;
case 3:
afuera = (px - 1) < 0 || (py - 1) < 0;
break;
case 4:
afuera = (px + 1) > 7 || (py - 1) < 0;
break;
}
}

and it keeps coming up this error message, I wish someone could help me:

Arduino: 1.5.6-r2 (Windows 7), Placa:"Arduino Uno"

funciones.ino: In function 'boolean afuera(int, int, int)':
funciones:9: error: assignment of function 'boolean afuera(int, int, int)'
funciones:9: error: cannot convert 'bool' to 'boolean ()(int, int, int)' in assignment
funciones:12: error: assignment of function 'boolean afuera(int, int, int)'
funciones:12: error: cannot convert 'bool' to 'boolean ()(int, int, int)' in assignment
funciones:15: error: assignment of function 'boolean afuera(int, int, int)'
funciones:15: error: cannot convert 'bool' to 'boolean ()(int, int, int)' in assignment
funciones:18: error: assignment of function 'boolean afuera(int, int, int)'
funciones:18: error: cannot convert 'bool' to 'boolean ()(int, int, int)' in assignment

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

afuera is the name of a function. You can't assign a value to it.

I think you mean to use "return" there...

ohh I forgot, thanks!!!

afuera

is spanish for "outside".

some thoughts.

boolean afuera(int px, int py, int dir) 
{
  switch (dir) 
  {
    case 1:  return (px < 1)  ||  (py > 6);  // remove the math
    break;
 ....
  }
  return false; // ????
}

The switch statement has no default, which implies that dir = {1,2,3,4} ==> dir could be a 1 byte datatype?

you need to add a return true/false in the end of the function to make the code robust.

As robtillaart pointed out, a switch doesn't know what to do with a value that doesn't have a corresponding case value, so it essentially ignores. it. As a general rule, I would always include a default statement block to cover such situations:

switch (dir) [
   case 1:
      //whatever case 1 should do...
      break;
   case 2:
      //whatever case 2 should do...
      break;
   case 3:
      //whatever case 3 should do...
      break;
   // more cases perhaps...
   default:
      Error(dir);   // Probably should never be here, so complain about it.
      break;
}

In this example, you might write an error-processing function, Error(dir), that passes in the value that doesn't match a case value for dir.