AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Little optimization (https://forums.alliedmods.net/showthread.php?t=321053)

Napoleon_be 01-22-2020 10:02

Little optimization
 
Is there anyway that i can do this in just one line? I've been trying all different things but i can't seem to get it to work.

PHP Code:

if(get_pcvar_num(pSounds))
{
    
client_cmd(iAttacker"mp3 play %s"szSound);



This is something i'd use, but the last part "DO NOTHING" needs to be changed since it makes no sense
PHP Code:

(get_pcvar_num(pSounds) ? client_cmd(iAttacker"mp3 play %s"szSound) : client_cmd(iAttacker"DO NOTHING")); 


JocAnis 01-22-2020 10:57

Re: Little optimization
 
your example in 'else' got me thinking of:
Code:

(get_pcvar_num(pSounds) ? client_cmd(iAttacker, "mp3 play %s", szSound))
but i get you meant other way...im also interested in this one line solution

HamletEagle 01-22-2020 11:18

Re: Little optimization
 
Why in the world you want an one line solution?
How in the world would that be an optimization? Less lines has nothing to do with how fast the code is. You should try to write clear and readable code, not short code. Short code is not a goal, if the plugin ends up short that's cool, if it doesn't then it's perfectly fine.
Funny enough both the if check and the ternary operator would likely be translated to the same assembly instructions by the compiler.

Don't waste your time trying to fix something that's not broken.

Napoleon_be 01-22-2020 11:41

Re: Little optimization
 
Quote:

Originally Posted by HamletEagle (Post 2681248)
Why in the world you want an one line solution?
How in the world would that be an optimization? Less lines has nothing to do with how fast the code is. You should try to write clear and readable code, not short code. Short code is not a goal, if the plugin ends up short that's cool, if it doesn't then it's perfectly fine.
Funny enough both the if check and the ternary operator would likely be translated to the same assembly instructions by the compiler.

Don't waste your time trying to fix something that's not broken.

Okay thanks


All times are GMT -4. The time now is 02:42.

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