AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reduce code on switch case (https://forums.alliedmods.net/showthread.php?t=281842)

Syturi0 04-22-2016 13:17

Reduce code on switch case
 
PHP Code:

public Menu_1_Handler(idMenuitem)
{
    switch(
item)
    {
        ...

        case 
20:
        {
            
Menu_2(id)
            
client_cmd(id"messagemode Test")
            
g_Test[id] = false
        
}
        case 
21:
        {
            
Menu_2(id)
            
client_cmd(id"messagemode Test")
            
g_Test[id] = false
            g_Test2
[id] = true
        
}
        case 
MENU_EXITMenu_0(id)
    }

    
menu_destroy(Menu)


Is there any way i can achieve this whiout having to repeat:
PHP Code:

Menu_2(id)
client_cmd(id"messagemode Test")
g_Test[id] = false 

on both cases?


I know i can do this:
PHP Code:

case 2021

But "case 21" have "g_Test2[id] = true" and "case 20" doesnt.

Black Rose 04-22-2016 13:37

Re: Reduce code on switch case
 
Code:
case 20, 21: ... if ( item == 21 )    g_Test2[id] = true

Syturi0 04-22-2016 13:37

Re: Reduce code on switch case
 
Quote:

Originally Posted by Black Rose (Post 2413218)
Code:
case 20, 21: ... if ( item == 21 )    g_Test2[id] = true

Thank you!


All times are GMT -4. The time now is 18:34.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.