Raised This Month: $51 Target: $400
 12% 

Wich method is better?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zeus
Senior Member
Join Date: Jul 2008
Old 04-12-2011 , 08:02   Wich method is better?
Reply With Quote #1

This
Code:
public init()
{
       if(var==a)
            function_a()
       else if(var=b)
            function_b()
}

public fuction_a()
        do something

public fuction_b()
        do some other things
Or this
Code:
public init()
{
       if(var==a)
            function(a)
       else if(var=b)
            function(a)
}

public fuction(x)
        do something with x
zeus is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 04-12-2011 , 08:34   Re: Wich method is better?
Reply With Quote #2

It depends what you want to do...
reinert is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 04-12-2011 , 08:35   Re: Wich method is better?
Reply With Quote #3

Depends on what you're doing.
Code:
switch (var) {         case a: // Do stuff         case b: // Do stuff }
__________________
hleV is offline
zeus
Senior Member
Join Date: Jul 2008
Old 04-12-2011 , 11:42   Re: Wich method is better?
Reply With Quote #4

For example i have this code
Code:
public check(id)
{
    if(is_user_retarded(id))
          cmd_retard(id)
    else if(is_user_idiot(id))
          cmd_idiot(id)
}

public cmd_retard(id)
    client_print(id,print_chat,"You are retarded !!!")

public cmd_idiot(id)
    client_print(id,print_chat,"You are an idiot !!!")
Is it better if I do something like this?
Code:
public check(id)
{
    if(is_user_retarded(id))
          cmd_retard_or_idiot(id,1)
    else if(is_user_idiot(id))
          cmd_retard_or_idiot(id,2)
}

public cmd_retard_or_idiot(id,x)
{
    if(x==1)
        client_print(id,print_chat,"You are retarded !!!")
    else if(x==2)
        client_print(id,print_chat,"You are an idiot !!!")
}
zeus is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-12-2011 , 11:59   Re: Wich method is better?
Reply With Quote #5

There is not really one better.

You can do things differently. Don't know what you plan to do exactly, but you can use a var which contains the "status" of the player.

PHP Code:
enum UserStatus
{
    
UserNormal,
    
UserRetarded,
    
UserIdiot
};

UserStatusDescriptionUserStatus ][] =
{
    
"You are normal !!!",
    
"You are retarded !!!",
    
"You are an idiot !!!"
};

new 
UserStatus:Status33 ];

public 
checkid )
{
    new 
UserStatus:currentStatus Statusid ];
    
    if( 
currentStatus != UserNormal )
    {
        
client_printidprint_chatUserStatusDescriptioncurrentStatus ] )
    }

You get the idea.
__________________
Arkshine is offline
zeus
Senior Member
Join Date: Jul 2008
Old 04-14-2011 , 07:32   Re: Wich method is better?
Reply With Quote #6

Thx for help :d
zeus is offline
fmcTheKing
Member
Join Date: Feb 2011
Location: Brazil
Old 04-14-2011 , 19:18   Re: Wich method is better?
Reply With Quote #7

PHP Code:
(var == 'a') ?
    
function_a(a) :
    
function_b(a) ; 
__________________

fmcTheKing is offline
Send a message via MSN to fmcTheKing Send a message via Skype™ to fmcTheKing
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:09.


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