This is pretty minor, but it kinda bugs me…
I’m getting compiling warnings for “unreachable code detected.” And yeah, it is currently unreachable, but they are just little bits that we are supposed to have for good practice.
My function returns a sprite for a world map avatar. I have unreachable code in the form of my “break” lines between cases. I also have a final failsafe/default return value at the end of the function that is deemed unreachable.
I feel a bit torn here. On one hand, I don’t want to get these warnings about unreachable code every time I compile (and neither do I want to disable these in case I make unreachable code somewhere else,) and on the other hand I feel like those bits should be left in, as good practice, in case I ever make revisions that don’t execute as cleanly as I want.
Sprite FindCurrentSprite(byte thisFrame)
{
switch (facingAngle)
{
case float n when n >= 45 && n < 135 || (n <= -225 && n > -315):
if (thisFrame == 1)
return WalkingFrames.North1;
else if (thisFrame == 3)
return WalkingFrames.North3;
else
return WalkingFrames.North2;
break;
case float n when Mathf.Abs(n) >= 135 && Mathf.Abs(n) < 225:
if (thisFrame == 1)
return WalkingFrames.West1;
else if (thisFrame == 3)
return WalkingFrames.West3;
else
return WalkingFrames.West2;
break;
default:
case float n when (n >= 225 && n < 315) || (n <= -45 && n > -135):
if (thisFrame == 1)
return WalkingFrames.South1;
else if (thisFrame == 3)
return WalkingFrames.South3;
else
return WalkingFrames.South2;
break;
case float n when Mathf.Abs(n) >= 315 || Mathf.Abs(n) < 45:
if (thisFrame == 1)
return WalkingFrames.East1;
else if (thisFrame == 3)
return WalkingFrames.East3;
else
return WalkingFrames.East2;
break;
}
return WalkingFrames.South2;
}