Explanation needed.
#1

Hello,
I wanted to that "ternary operator",what is this?Please I need a explanation on this.
ThAnKs!
Reply
#2

Check this https://sampforum.blast.hk/showthread.php?tid=216730
Reply
#3

Hmm can you explain them to me step by step please.ThAnKs!
Reply
#4

Someone please explain them.
Reply
#5

pawn Код:
IsConnected[playerid] = (IsPlayerConnected(playerid)) ? 1 : 0;

(IsPlayerConnected(playerid)) is the if statement
? is pretty much the opening bracket
: is the else statement


For strings you'll need to enclose it in parenthesis, ex:

pawn Код:
PlayersRank[playerid] = (IsPlayerAdmin(playerid)) ? ("Administrator") : ("Player");
Reply
#6

Hmm I see.Anymore explanations?
Reply
#7

Well basically it's an if-statement in an expression. For example:
pawn Код:
new val = 4;
new otherval;
if(val == 8)
{
    othervalval = 6;
}
else
{
    othervalval = 12;
}
Could also be written as:
pawn Код:
new val = 4;
new otherval;
otherval = (val == 8) ? (6) : (12);
The hooks are optional, but I usually add them to keep code readable.

In the case of if-else if-else statements:
pawn Код:
if(a == 4)
{
    b = 8;
}
else if(a == 3)
{
    b = 13;
}
else
{
    b = 2;
}
becomes...

pawn Код:
b = (a == 4) ? (8) : (a == 3) ? (13) : 2;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)