Question regarding case and if statement.
#1

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?
Reply
#2

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

Reply
#3

Damn, okay! Thanks for you quick reply..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)