Switch Case driving me potty

So before my laptop meets the wall…

I have a script which is attached to a GUITexture, essentially a button used to execute a command. As part of this script, I have the following:

function SetupAction(){
	switch(this.name)
		{
		case "actionAxe":	
			Debug.Log("Found Axe in "+this.name);
			ATT = 7;
		case "actionTeeth":
			Debug.Log("Found Teeth in "+this.name);
			ATT = 1;
		default:
			Debug.Log("NONE found.");
		}
}

So all I want to do is check the icons name, and depending on what it is, setup that icons attack strength etc (ie configure its skill). However when running, I get this:

Found Axe in actionAxe
Found Teeth in actionAxe
NONE found.
Found Teeth in ActionTeeth.
NONE found.

Both objects are then assigned a value of 1, which isn’t right.

I’m going mad here. Someone PLEASE help put me out of my misery!

Thanks,

Dan

You need breaks in there.

function SetupAction(){
	switch(this.name)
		{
		case "actionAxe":	
			Debug.Log("Found Axe in "+this.name);
			ATT = 7;
                        break;
		case "actionTeeth":
			Debug.Log("Found Teeth in "+this.name);
			ATT = 1;
                        break;
		default:
			Debug.Log("NONE found.");
		}
}

Otherwise it will continue on to the next statement.

:eyes: And no tutorial chose to tell me this? How strange! Thanks very much sir. I’m not exactly sure why you would need to do that (normally Select Case, etc, find a match, execute and then stop don’t they?).

It is confusingly written on the wiki but UnityScript, unlike C#, but just like C/C++, requires a break to terminate the case. C# will run on only if the case is empty:

http://www.unifycommunity.com/wiki/index.php?title=Head_First_into_Unity_with_UnityScript#Switch_statements_do_not_run_on
http://www.unifycommunity.com/wiki/index.php?title=UnityScript_Keywords#switch

P.S. Drunk, so expect corrections to whatever I say while I incorrectly answer the wrong forum thread. I will revise history if need be!

Rule number one, never edit drunken posts. :wink:

Yeah it just really confuses me because this seems to work without breaks:

switch(ActionType){
case(“AttackMelee”):
AttackMelee();
case (“AttackRanged”):
AttackRanged();
case (“Heal”):
Heal();
}

I’ll start putting breaks in anyway as a precaution. Thanks!

The Lloyd giveth and the Lloyd taketh away… what’s the point in being a Time Lloyd if you cannot revise history every once in a while?

Glad you figured out your switch problem, I wanted to post… puts on sunglasses** Justin Case** the usage of break wasn’t clear.

** You see what I did there?

sigh Cheers anyway. Now go and write a Drunken Distraction for your sig…