Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 5 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking For Help? Look No More!
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#34
RE: Looking For Help? Look No More!

A switch statement is kinda like a list of if statements, but kept in a nice neat form.
Spoiler below!

switch(Number_X){

}
is like saying
if(Number_X){

}
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.
Smile

Edit: just a couple of scripts to see how if's differ from switch! Smile
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;
}


(This post was last modified: 08-30-2011, 12:57 PM by DRedshot.)
08-30-2011, 12:42 PM
Find


Messages In This Thread
Looking For Help? Look No More! - by Kyle - 08-28-2011, 03:35 PM
RE: Looking For Help? Look No More! - by Kyle - 08-28-2011, 03:51 PM
RE: Looking For Help? Look No More! - by Kyle - 08-28-2011, 04:19 PM
RE: Looking For Help? Look No More! - by Elven - 08-28-2011, 07:42 PM
RE: Looking For Help? Look No More! - by Elven - 08-28-2011, 08:21 PM
RE: Looking For Help? Look No More! - by Legato - 08-28-2011, 10:42 PM
RE: Looking For Help? Look No More! - by Legato - 08-29-2011, 12:54 AM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 12:51 PM
RE: Looking For Help? Look No More! - by rybray - 08-29-2011, 05:18 PM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 05:54 PM
RE: Looking For Help? Look No More! - by rybray - 08-29-2011, 06:11 PM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 06:19 PM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 06:33 PM
RE: Looking For Help? Look No More! - by ZRPT - 08-29-2011, 06:41 PM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 07:33 PM
RE: Looking For Help? Look No More! - by Kyle - 08-29-2011, 08:29 PM
RE: Looking For Help? Look No More! - by zeravia - 08-29-2011, 09:15 PM
RE: Looking For Help? Look No More! - by DRedshot - 08-30-2011, 12:42 PM
RE: Looking For Help? Look No More! - by Kyle - 08-30-2011, 12:47 PM
RE: Looking For Help? Look No More! - by DRedshot - 08-30-2011, 12:59 PM
RE: Looking For Help? Look No More! - by Elven - 08-30-2011, 02:46 PM
RE: Looking For Help? Look No More! - by Kyle - 08-30-2011, 03:43 PM
RE: Looking For Help? Look No More! - by Elven - 08-30-2011, 03:45 PM
RE: Looking For Help? Look No More! - by Kyle - 08-30-2011, 04:22 PM
RE: Looking For Help? Look No More! - by Elven - 08-30-2011, 04:38 PM
RE: Looking For Help? Look No More! - by ZRPT1 - 08-30-2011, 05:23 PM
RE: Looking For Help? Look No More! - by Kyle - 08-30-2011, 05:31 PM
RE: Looking For Help? Look No More! - by ZRPT1 - 08-30-2011, 05:34 PM
RE: Looking For Help? Look No More! - by Kyle - 08-30-2011, 06:14 PM
RE: Looking For Help? Look No More! - by ZRPT1 - 08-30-2011, 06:24 PM
RE: Looking For Help? Look No More! - by Kyle - 08-31-2011, 03:13 AM
RE: Looking For Help? Look No More! - by xiphirx - 08-31-2011, 03:46 AM
RE: Looking For Help? Look No More! - by xiphirx - 08-31-2011, 04:06 AM
RE: Looking For Help? Look No More! - by xiphirx - 08-31-2011, 05:04 AM
RE: Looking For Help? Look No More! - by DRedshot - 08-31-2011, 11:58 AM
RE: Looking For Help? Look No More! - by TheBaker - 09-01-2011, 06:39 PM
RE: Looking For Help? Look No More! - by rybray - 09-03-2011, 03:01 PM
RE: Looking For Help? Look No More! - by Selyp - 09-04-2011, 12:45 AM
RE: Looking For Help? Look No More! - by rybray - 09-04-2011, 06:07 PM
RE: Looking For Help? Look No More! - by Kyle - 09-05-2011, 12:45 PM
RE: Looking For Help? Look No More! - by Kyle - 09-05-2011, 07:04 PM
RE: Looking For Help? Look No More! - by xiphirx - 09-06-2011, 03:28 AM
RE: Looking For Help? Look No More! - by JMFStorm - 09-07-2011, 05:23 AM
RE: Looking For Help? Look No More! - by DRedshot - 09-15-2011, 03:12 PM
RE: Looking For Help? Look No More! - by DRedshot - 09-16-2011, 10:51 AM
RE: Looking For Help? Look No More! - by Bearscar - 09-16-2011, 10:57 AM
RE: Looking For Help? Look No More! - by Kyle - 09-16-2011, 11:05 AM
RE: Looking For Help? Look No More! - by Bearscar - 09-16-2011, 11:24 AM
RE: Looking For Help? Look No More! - by Leu Radu - 09-16-2011, 09:22 PM
RE: Looking For Help? Look No More! - by Dilzilla - 09-16-2011, 11:56 PM
RE: Looking For Help? Look No More! - by Kman - 09-17-2011, 05:49 AM
RE: Looking For Help? Look No More! - by Elven - 09-17-2011, 09:35 PM
RE: Looking For Help? Look No More! - by Elven - 09-17-2011, 11:50 PM



Users browsing this thread: 1 Guest(s)