I recently had someone message me privately asking if there was a ternary operator in agk.
For those not in the know; a ternary operator looks something like this:
canVote = age>=18 ? 1 : 0
and it's a shorthand way of saying this:
if age >= 18
canVote = 1
else
canVote = 0
endif
The answer is, of course, no. AppGameKit does not have a ternary operator. However,
it can still be done. You just need to replace the
? with
and and the
: with
or
So in agk the ternary operator above can be written as:
canvote = age >= 18 and 1 or 0
It's a useful tip for anyone that doesn't know it, so I thought I'd share it here.
[EDIT] Caveat: It only works with integers but it's still a useful tool to have in your bag