Whats Better?
#1

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")
}
Reply
#2

There is not really a "Better" way of doing that.
Reply
#3

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
Reply
#4

How would i do that, For 2 if?
Like

if(IsPlayerAdmin
&
if(IsPlayerInAnyVehicle

How would i do that?
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)