Trying to learn Ternary Operator, but failed! - 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: Trying to learn Ternary Operator, but failed! (
/showthread.php?tid=261575)
Trying to learn Ternary Operator, but failed! -
Basicz - 14.06.2011
pawn Code:
public OnPlayerRequestClass( playerid, classid )
{
SetPlayerColor( playerid, ( classid == 0 ) : 0xFFFFFFFF ? ( classid == 1 ) : 0xAAAAAAAA );
return 1;
}
How to get this working without any errors!
Re: Trying to learn Ternary Operator, but failed! -
Skaizo - 14.06.2011
put eror
Re: Trying to learn Ternary Operator, but failed! -
Basicz - 14.06.2011
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
Re: Trying to learn Ternary Operator, but failed! -
Calgon - 14.06.2011
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.
Re: Trying to learn Ternary Operator, but failed! -
Skaizo - 14.06.2011
SetPlayerColor(playerid, (classid == 0) ? 0xFFFFFFFF : (classid == 1) ? 0xAAAAAAAA);
Re: Trying to learn Ternary Operator, but failed! -
Basicz - 14.06.2011
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....................