Whats Better? - 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: Whats Better? (
/showthread.php?tid=126085)
Whats Better? -
Torran - 07.02.2010
What is better for all
if( things?
pawn Код:
if(IsPlayerAdmin(playerid) return SendClientMessage(playerid, COLOR_RED, "You are not administrator");
Or
pawn Код:
if(IsPlayerAdmin(playerid)
{
// Stuff
}
else
{
SendClientMessage(playerid, COLOR_RED, "You are not administrator")
}
Re: Whats Better? -
[HiC]TheKiller - 07.02.2010
There is not really a "Better" way of doing that.
Re: Whats Better? -
mansonh - 07.02.2010
Efficiency wise it shouldn't really matter.
Because your code will evaluate the first if, and if it fails will jump strait to the else if (machine language level is a wonderful thing).
However if you put the if->return first then you end up only doing the one test and return without the jump (efficiency wise there isn't much significant difference, unless the if(){code} is extremely long, to require loading(again very very unlikely, unless you have a really shitty 10 year old server).
But personally I would go with
pawn Код:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not administrator");
//Admin stuff
Re: Whats Better? -
Torran - 07.02.2010
How would i do that, For 2 if?
Like
if(IsPlayerAdmin
&
if(IsPlayerInAnyVehicle
How would i do that?
Re: Whats Better? -
mansonh - 07.02.2010
if(isplayeradmin) return /*you are not an admin...*/;
if(!isplayerinanyvehicle) return /*you are not in vehicle...*/;
now they are in a vehicle... do what you will