SA-MP Forums Archive
Check or direct function executing? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Check or direct function executing? (/showthread.php?tid=233463)



Check or direct function executing? - OldDirtyBastard - 01.03.2011

This may sound a bit minor but i wanna ask:
What would be better to use, a check or the function should get executed right away?

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(GetPlayerWantedLevel(playerid) > 0)
    {
        SetPlayerWantedLevel(playerid, 0);
    }
    return 1;
}
or directly

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    SetPlayerWantedLevel(playerid, 0);
    return 1;
}
Thanks, regards.


AW: Check or direct function executing? - Nero_3D - 01.03.2011

I would prefer the second methode

but you could test what methode faster is


Re: Check or direct function executing? - OldDirtyBastard - 01.03.2011

Ill do that, thanks.


Re: Check or direct function executing? - JaTochNietDan - 01.03.2011

Well obviously the second one is faster in general, because the worst case scenario in the first example is that you're calling 2 functions, the second example will always result in one function being called.

However! There is another factor, what if the checking function executes faster than the setting function? Then in some cases it may be better to do the check, but generally in most cases, it is not. At least not for a single function.