Raised This Month: $32 Target: $400
 8% 

Help / Support Condition "if, else if", Do not work properly.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Death Stroke
Junior Member
Join Date: Mar 2021
Location: Algeria.
Old 06-18-2022 , 09:34   Condition "if, else if", Do not work properly.
Reply With Quote #1

Hi there,

i'm encountering problem while using the condition. I have Human classes wich i like to assign every cso knife i have to it. I tried doing it with native inside human classes sma, But there is issues.

Code:
public zp_user_humanized_post(id, class)
{
	if(class = g_hclass1){
	Getj9(id);
         }
	 
	else if (class = g_hclass2){
	get_dragonsword(id);
         }
}
The problem is when i select g_hclass1 it gives me dragonsword same with class two, i want every class has it own knife. So what should i do to avoid this issues?

thanks in advance.
Death Stroke is offline
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 06-19-2022 , 15:28   Re: Condition "if, else if", Do not work properly.
Reply With Quote #2

I think its safe to use switch instead of if and else if, something like
PHP Code:
public zp_user_humanized_post(id, class)
{
    if (
is_user_alive (id))        // prevent disconnect errors
    
{
        new class = 
zp_get_user_class (id); // just and example i dont know what way of getting class id ZP has
        
switch ( class )
        {
            case 
g_hclass1: { Getj9(id) };
            case 
g_hclass2: { get_dragonsword(id) };
        }
    }
    break;

https://wiki.alliedmods.net/Optimizi..._instead_of_If
Normally it should work since it said there that
Code:
Switch instead of If
If you can, you should use switch cases instead of if. This is because for an if statement, the compiler must branch to each consecutive if case. Using the example from above, observe the switch version:
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers

Last edited by CryWolf; 06-19-2022 at 15:35. Reason: nvm.
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
Death Stroke
Junior Member
Join Date: Mar 2021
Location: Algeria.
Old 06-23-2022 , 10:35   Re: Condition "if, else if", Do not work properly.
Reply With Quote #3

Quote:
Originally Posted by CryWolf View Post
I think its safe to use switch instead of if and else if, something like
PHP Code:
public zp_user_humanized_post(id, class)
{
    if (
is_user_alive (id))        // prevent disconnect errors
    
{
        new class = 
zp_get_user_class (id); // just and example i dont know what way of getting class id ZP has
        
switch ( class )
        {
            case 
g_hclass1: { Getj9(id) };
            case 
g_hclass2: { get_dragonsword(id) };
        }
    }
    break;

https://wiki.alliedmods.net/Optimizi..._instead_of_If
Normally it should work since it said there that
Code:
Switch instead of If
If you can, you should use switch cases instead of if. This is because for an if statement, the compiler must branch to each consecutive if case. Using the example from above, observe the switch version:
This was useful, thank you very much!
Death Stroke is offline
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 17:26.


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