Trying to learn Ternary Operator, but failed!
#1

pawn Code:
public OnPlayerRequestClass( playerid, classid )
{
    SetPlayerColor( playerid, ( classid == 0 ) : 0xFFFFFFFF  ? ( classid == 1 ) : 0xAAAAAAAA );
    return 1;
}
How to get this working without any errors!
Reply
#2

put eror
Reply
#3

pawn Code:
error 001: expected token: ",", but found ":"
error 029: invalid expression, assumed zero
warning 206: redundant test: constant expression is non-zero
warning 213: tag mismatch
warning 215: expression has no effect
error 001: expected token: ";", but found ")"
fatal error 107: too many error messages on one line
Reply
#4

You are only making two comparisons...

pawn Code:
SetPlayerColor(playerid, (classid == 0) ? 0xFFFFFFFF : 0xAAAAAAAA);
I'd say you're better off using a switch, instead of the ternary operator to declutter your code for this operation though.
Reply
#5

SetPlayerColor(playerid, (classid == 0) ? 0xFFFFFFFF : (classid == 1) ? 0xAAAAAAAA);
Reply
#6

Quote:
Originally Posted by Calg00ne
You are only making two comparisons...

pawn Code:
SetPlayerColor(playerid, (classid == 0) ? 0xFFFFFFFF : 0xAAAAAAAA);
I'd say you're better off using a switch, instead of the ternary operator to declutter your code for this operation though.
Thanks! For the information.

Quote:
Originally Posted by RSS Cops_sandu
SetPlayerColor(playerid, (classid == 0) ? 0xFFFFFFFF : (classid == 1) ? 0xAAAAAAAA);
....... Spammer!
That code looks the same as mine....................
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)