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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Intro
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: Intro

A switch-statement is like an array of if-statements. They're not very complicated when you know them.

Here's a short example:

PHP Code: (Select All)
int var = 1;

switch(var) {
    case 
0: {
        
//Run script for case 0.
        
break;
    }
    case 
1: {
        
//Run script for case 1. This one will run because var == 1.
        
break;
    }
    case default: {
        
//Run script if no matching case is found.
        
break;
    }


What happens here is that the switch will use the var variable as its testing value. Depending on the value of var, different cases will run.

The break; keyword is required so that you don't run more than one case. If you do not have break, it will run case 1 and case default after case 0 if 0 was accepted. If 0 was denied, but 1 was accepted (which is the case here), then it will run case 1 and case default (I believe).

If you're more familiar with if-statements, here's an example that does the exact same.

PHP Code: (Select All)
int var = 1;

if(var == 
0) {
    
//Run script for case 0.
}
else if(var == 
1) {
    
//Run script for case 1. This one will run because var == 1.
}
else if(var < 
|| var > 1) {
    
//Run script if var does not match above. This one runs if var is less than 0 or more than 1, EG anything but the above if-statements.


(This post was last modified: 01-01-2015, 06:25 AM by Mudbill.)
01-01-2015, 06:25 AM
Find


Messages In This Thread
Intro - by ethics - 12-31-2014, 07:45 PM
RE: Intro - by Mudbill - 12-31-2014, 07:52 PM
RE: Intro - by ethics - 12-31-2014, 10:41 PM
RE: Intro - by Radical Batz - 01-01-2015, 12:03 AM
RE: Intro - by Mudbill - 01-01-2015, 06:25 AM



Users browsing this thread: 1 Guest(s)