• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ternary Operator Basics
#5
(2021-04-30, 06:11 PM)kemper Wrote:

(2021-04-28, 07:58 AM)Shadow Wrote:

Good tutorial, you just forgot to mention that ternary operator supports multiple conditions.

For example:

PHP Code:
[/font][/size][/color]

[
color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]SendClientMessage(playerid, -1, playerData[playerid][pAdmin] == 1 ? "Admin lvl 1" : playerData[playerid][pAdmin] == 2 ? "Admin lvl 2" : playerData[playerid][pAdmin] == 3 ? "Admin lvl 3" : "Admin lvl 4");[/font][/size][/color]

[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif] 




And btw, you don't need brackets, just own preference.





In your example the readability of the code is suffering. Nesting of conditions is not a good idea.





I know, and I completely agree with you. Although the readability in ternary operator is a mess, this is a tutorial about it, and this should be mentioned.?

I remember when I was learning how ternary operator works in PAWN, I almost didn't find that example... I used to think that ternary operator accepts only one condition with two results...
  Reply


Messages In This Thread
Ternary Operator Basics - by RhaegarX - 2021-01-20, 07:29 PM
RE: Ternary Operator Basics - by Shadow - 2021-04-28, 07:58 AM
RE: Ternary Operator Basics - by RhaegarX - 2021-04-30, 12:22 AM
RE: Ternary Operator Basics - by kemper - 2021-04-30, 06:11 PM
RE: Ternary Operator Basics - by Shadow - 2021-05-03, 02:40 PM

Forum Jump: