A switch statement is kinda like a list of if statements, but kept in a nice neat form.
Spoiler below!
is like saying
The only difference is what happens next.
With an if statement you write the condition as
Spoiler below!
if((Number_X) == 1){
// Number_X == 1
}
But with a switch statement, it goes like this:
switch(Number_X){
case 1:
// Number_X == 1
break;
}
think of "case 1:" as the computer saying "if the value is 1"
so
switch(Number_Y){
case 1:
// Do this stuff if Number_Y is 1
break;
case 2:
// Do this stuff if Number_Y is 2
break;
case 3:
// Do this stuff if Number_Y is 3
break;
}
is like the computer saying
"Get the value of "Number_Y" for me!
If it is 1, do the stuff in case 1:
If it is 2, do the stuff in case 2:
If it is 3, do the stuff in case 3:
If it is x, do the stuff in case x:"
once you understand how it works look
here
Hopefully this helps! think of it as multiple if statements in a row.
Edit: just a couple of scripts to see how if's differ from switch!
Spoiler below!
How it looks in switch format
switch(GetLocalVarInt("Number")){
case 1:
PlaySoundAtEntity("" , "Boom.snt" , "Door_1" , 0.5f , false);
break;
case 2:
AddTimer("Delay_1" , 5.5f , "Timer");
break;
case 3:
CreateParticleSystemAtEntity("" , "ps_smoke.ps" , "Area_3" , false);
break;
}
is the same as
if(GetLocalVarInt("Number")==1){
PlaySoundAtEntity("" , "Boom.snt" , "Door_1" , 0.5f , false);
return;
}
if(GetLocalVarInt("Number")==2){
AddTimer("Delay_1" , 5.5f , "Timer");
return;
}
if(GetLocalVarInt("Number")==3){
CreateParticleSystemAtEntity("" , "ps_smoke.ps" , "Area_3" , false);
return;
}