Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Tutorials Ternary Operator Basics

 
  • 0 Vote(s) - 0 Average
Ternary Operator Basics
Shadow
Offline

Real Shadow
Posts: 4
Threads: 0
Joined: Apr 2019
Reputation: 0
Location: Croatia
#5
2021-05-03, 02:40 PM (This post was last modified: 2021-05-03, 02:41 PM by Shadow.)
(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...
« Next Oldest | Next Newest »



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

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode