- Home /
Question by
saberboy117 · Apr 17, 2011 at 05:43 PM ·
returnwarningbreakswitch-case
unreachable code error Dosent seem right!
Assets/Scripts/Player/Mission Over Gui.js(14,1): BCW0015: WARNING: Unreachable code detected. this error dosent seem right, it works perfectly! thats the error I get for this code:
function GetMedal(a : float){
var ar : float = _G.CurrentMissionStatus.ra;
var rank : int=0;
if (a >= ar){rank+=3;}
else if (a >= ar/2) {rank+=2;}
else if (a >= ar/3) {rank++;}
if (_G.CurrentMissionStatus.Kills >= _G.CurrentMissionStatus.rk) {rank+=3;}
else if (_G.CurrentMissionStatus.Kills >= Mathf.Round(_G.CurrentMissionStatus.rk/2)){rank+=2;}
else if (_G.CurrentMissionStatus.Kills >= Mathf.Round(_G.CurrentMissionStatus.rk/3)){rank++;}
switch(rank){//suposed error here
case 0:
_G.CurrentMissionStatus.medal = 0;
return "No Medal Awarded";
break;
case 1:
_G.CurrentMissionStatus.medal = 1;
return "Bronze Medal Awarded";
break;
case 2:
_G.CurrentMissionStatus.medal = 1;
return "Bronze Medal Awarded";
break;
case 3:
_G.CurrentMissionStatus.medal = 2;
return "Silver Medal Awarded";
break;
case 4:
_G.CurrentMissionStatus.medal = 2;
return "Silver Medal Awarded";
break;
case 5:
_G.CurrentMissionStatus.medal = 3;
return "Gold Medal Awarded";
break;
case 6:
_G.CurrentMissionStatus.medal = 3;
return "Gold Medal Awarded";
break;
}
}
thanks
Comment
Best Answer
Answer by Sam Bauwens · Apr 17, 2011 at 05:50 PM
It's not an error, just a warning. The reason is that all the break;
statements can't be accessed because they are after a return
statement, so they are useless. You can remove those statements.
IIRC JS has a bug where it will whine if you remove the breaks also. http://answers.unity3d.com/questions/49331/javascript-switch-returns-warn-for-unreachable-code You'll have (for each case) to set a variable, break, and outside the switch return the result.