Posted: 8th Jan 2022 12:23
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:
+ Code Snippet
canVote = age>=18 ? 1 : 0

and it's a shorthand way of saying this:
+ Code Snippet
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:
+ Code Snippet
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
Posted: 8th Jan 2022 13:57
You should be able to just,

canvote = age >= 18
Posted: 8th Jan 2022 15:37
That works too ... and it's more elegant.
I was just trying to make it more like a ternary operator but it clearly isn't required.

That's code blindness for you!
I'd been playing around trying to make something that performed like a ternary operator and was so happy when I got it working that I didn't notice the very obvious basics!!!