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!
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#41
RE: Looking For Help? Look No More!

(08-30-2011, 02:43 PM)Mooserider Wrote: Can you please explain for statements to me in a way I can understand? Big Grin
Every time I see an explanation of it my brain explodes Tongue I just don't get it.

Thanks in advance! Smile It's really kind of you to offer help to people. Smile

A "switch" statement is very much like an "if" statement. A switch statement organizes data in a different way. It can be used mostly when there are many possible outcomes, or things that could happen.

If you type "switch" when in an ".hps" script file, you will notice that it changes color (If you have the right ".hps" package for Notepad++ or course.), that's how you know that it can be used for something important.

Let us say that you have a number variable, and this number variable will be changed. We need to find a way to know what the current value of the variable is.

Here we have a variable:

int x = 1;

Here the value is changed:

x = 2;

Then we check and see what it equals in case if we don't know what it really equals. Like if the player picks a number between 1 and 10, we would need to know which one the player chose.

Now we start the "switch" statement.

void OnStart()
{
     int x = 1;
     x = 2;
     switch(x)
     {
          
     }
}

You might be wondering, why is there parentheses after the "switch" statement and the variable x inbetween is declared?

Well, since we know that the value of x equals 2, we could have it like this:

switch(2)
{
    
}

That wouldn't work correctly because 2 always equals 2, and variable x isn't supposed to be constant or else there would be no point in having a "switch" statement.

Now I'll introduce you something called a "case". A case is like a piece of an "if" statement. There can be as many cases as you want there to be. It is normally listed "case 1:", "case 2:"... ect. But you can also have it be a string after the case, like "case 'Name':", where it checks if the value of the switch's variable is equal to "Name". There has to be single quotes ( ' ) between it. To end a certain "case", you have to type "break;" at the end of it. I'm going to show you what the differences between an "if" statement and a "switch" statement looks like, while demonstrating where each part came from.

"Switch" statement:

void OnStart()
{
int x = 1;
x = 2;
switch(x)
{
case 1:
{
// Have something to happen here, if x = 1.
break;
}
case 2:
{
// Have something to happen here, if x = 2.
break;
}
default: // Used like an "else" statement.
{
// Have something to happen here, if x doesn't equal 1 or 2.
}
}


"If" statement:

void OnStart()
{
int x = 1;
x = 2;
if (x == 1)
{
// Have something to happen here, if x = 1.
}
if (x == 2)
{
// Have something to happen here, if x = 2.
}
else
{
// Have something to happen here, if x doesn't equal 1 or 2.
}
}

I hope this helps! Big Grin

(This post was last modified: 08-30-2011, 03:22 PM by Kyle.)
08-30-2011, 03:21 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)