This time i’ll show you guys how to use the ternay operator given by many languages like C or PAWN.
This time we will only talk about the condititonal operator to replace if-statements. There are also ways to perform other actions using nested ternary operator statements.
It is commonly referred as the conditional operator, inline if (iif), or ternary if. An expression x ? y : a evaluates to y if the value of x is true, and otherwise to a.
Brief example, comparing 2 numbers using if-statement.
Using our beloved ternary operator makes it much simplier and shorter, and that’s it.
Now some examples from my gamemodes, in this case my spectate system to spectate a random player.
Now again to shorten this we’ll use ternary operator again.
So in conclusion we figured out we can economize letters using ternary operators instead of if-statement in some cases.
For now that’s it, but during the next days i’ll introduce some more advanced examples using the ternary operator in PAWN.