SA-MP Forums Archive
Question regarding case and if statement. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question regarding case and if statement. (/showthread.php?tid=595303)



Question regarding case and if statement. - CrazyChoco - 01.12.2015

Hello, can I do this:
pawn Код:
if(UserAccount[playerid][Adminlevel] >= 1)
{

}
How do I make that inside a switch function..

case 1.. (How do i tell it to check if the level is higher than 1.. in this case?


Re: Question regarding case and if statement. - Vince - 01.12.2015

Switch cases are not fall-through in Pawn so you can't do this. In most other languages a switch must explicitly be broken, which allows for something like:

PHP код:
switch(level)
{
    case 
5
        
$this->AddPermission(...);
    case 
4:
        
$this->AddPermission(...);
    case 
3:
        
$this->AddPermission(...);
    case 
2:
        
$this->AddPermission(...);
    case 
1:
        
$this->AddPermission(...);
        
$this->AddPermission(...);

The closest you can get is a bunch of nested if-statements, but this can get very ugly very quickly if you have lots of levels.
PHP код:
if(level >= 1)
{
    if(
level >= 2)
    {
        if(
level >= 3)
        {
            
// etc, very ugly
        
}
    }




Re: Question regarding case and if statement. - CrazyChoco - 01.12.2015

Damn, okay! Thanks for you quick reply..