I am trying to provide a communication method using Arduino/Wiring to make two objects move with two joysticks.
This is the method that I use for the communication:
public PVector serialEvent(Serial myPort) {
PVector direction = new PVector(0, 0);
PVector directionD = new PVector(0, 0);
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
if (myString != null) {
String [] dataJoystick1 = split(myString, ",");
// println (dataJoystick);
try {
direction.set(Float.parseFloat(dataJoystick1[0]), Float.parseFloat(dataJoystick1[1]), 0);
directionD.set(Float.parseFloat(dataJoystick1[2]), Float.parseFloat(dataJoystick1[3]), 0);
}
catch(NumberFormatException e) {
}
movimiento=direction;
movimientoD=directionD;
//==============================PJ1========
if (direction.x==0) {
movimiento.set(0, movimiento.y, 0);
}
if (direction.y==0) {
movimiento.set(movimiento.x, 0, 0);
}
}
//==============================PJ2========
if (directionD.x==0) {
movimiento.set(0, movimiento.y, 0);
}
if (directionD.y==0) {
movimiento.set(movimiento.x, 0, 0);
}
return direction;
return directionD;
}
As you can see, I have two PVector
s for each character direction
and directionD
. However, when I run the code it gives me this error:
Unreachable code in the line return directionD;
return direction;
return directionD;
You cannot have two return statements like this without a condition. When the first return statement is executed, there is no chance to reach the second return statement. That's why there is an unreachable statement.