Raised This Month: $ Target: $400
 0% 

[ SOLVED ] Difference between the codes?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-11-2015 , 15:45   [ SOLVED ] Difference between the codes?
Reply With Quote #1

What is the difference between the codes?

Code:
public fw_TakeDamage(inflictor, victim, attacker, Float:damage) {     if(is_user_alive(attacker) && g_has_weapon[attacker] && get_user_weapon(attacker) == CSW_WPN)     {         SetHamParamFloat(bla bla bla);     } }

Code:
public fw_TakeDamage(inflictor, victim, attacker, Float:damage) {     if(!is_user_alive(attacker) || !g_has_weapon[attacker] || get_user_weapon(attacker) != CSW_WPN)         return HAM_IGNORED;     SetHamParamFloat(bla bla bla);     return; }
__________________









Last edited by CrazY.; 11-12-2015 at 06:21.
CrazY. is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-11-2015 , 16:10   Re: [ HELP ] Difference between the codes?
Reply With Quote #2

No difference

They both do sethamparamfloat only if the statements are true

Last edited by redivcram; 11-11-2015 at 16:13.
redivcram is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 11-11-2015 , 18:15   Re: [ HELP ] Difference between the codes?
Reply With Quote #3

The main difference is at below part:
Code:
if(is_user_alive(attacker) && g_has_weapon[attacker] && get_user_weapon(attacker) == CSW_WPN)
Code:
if(!is_user_alive(attacker) || !g_has_weapon[attacker] || get_user_weapon(attacker) != CSW_WPN)
The first code will make sure the attacker to fullfill all of checks to continue to next event while the second code will allow attacker to pass if he fulfill one of the checks.
zmd94 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-11-2015 , 20:02   Re: [ HELP ] Difference between the codes?
Reply With Quote #4

Which one is most recommended?
__________________








CrazY. is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 11-11-2015 , 20:07   Re: [ HELP ] Difference between the codes?
Reply With Quote #5

We can't recommend anything unless you tell us what you're trying to do.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 11-11-2015 at 20:25.
wickedd is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-11-2015 , 21:18   Re: [ HELP ] Difference between the codes?
Reply With Quote #6

I would do the first one because it's cleaner and more logical.

Code 1
PHP Code:
if ( all of these things are true )
   do 
this stuff 
Code 2
PHP Code:
if ( all of these things are true 
    exit 

do 
this stuff 
Sometimes code 2 makes sense depending on what kind of stuff is going on. But for a basic 2-3 line function, definitely code #1. There is no better from a performance perspective, it's really about taste.
__________________

Last edited by Bugsy; 11-11-2015 at 21:19.
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-12-2015 , 06:20   Re: [ HELP ] Difference between the codes?
Reply With Quote #7

Thanks for the help
__________________









Last edited by CrazY.; 11-12-2015 at 06:21.
CrazY. is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 11-12-2015 , 08:11   Re: [ SOLVED ] Difference between the codes?
Reply With Quote #8

Nevermind. ;)
zmd94 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:55.


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