Lots of times I want to do something like this:
if value < 0 then set flag to 1 otherwise set flag to 0
which ends up in KM looking something like this:
Is there some simpler way of doing this? Like a function that returns 1 or 0 depending on a condition like this hypothetical example:
where the function ISTRUE(some condition)
would return 1 if true, 0 if not.
@peternlewis I don't think there is a way to do this currently, and if not, could you add it sometime in the future? Thanks.
2 Likes
I cheat and use the shell to do this quickly ... probably not RAM efficient, but very quick to add as a saved action:
if [ "$KMVAR_Local_Diff" -lt 0 ]; then echo 1; else echo 0; fi
Save the results to Local_LeftFlag
and off you go. Note: I fully agree with the feature request for a way to do this natively :).
-rob.
1 Like
Airy
May 29, 2024, 10:23pm
3
Try this:
It works only with math formulas (calculations) not things like "if an app is running."
It's called the Ternary operator, and it can even be nested or used in sequences. I use it often.
Moreover, in your example, a<b returns 1 for True and 0 for False, so you can just assign "a<b" to some other value in any calculation.
5 Likes
I have no idea how I missed this. I use that operator all the time in JXA / JavaScript. You rock!! (As does @peternlewis for including this, of course.)
Thanks a million.
1 Like
tiffle
May 30, 2024, 11:04am
5
I had this post by @Nige_S bookmarked a while back
I keep finding myself trying to do conditionals like
(n > a AND n < b) OR (n > y AND n < z)
as
[booleanLogic]
...which, unsurprisingly, doesn't work.
Am I missing a trick? Example of where this would be useful here .
You can do it with ternaries (ignore the colours, I didn't define the variables)
[booleanTernary]
....but that feels clunky (and leaves me scratching my head when I look at it the next day!).
Proper ternaries example -- change Local_test, as it stands values of 2 or 6 are t…
1 Like
Airy
May 30, 2024, 4:55pm
6
DanThomas:
Thanks a million.
You're welcome. It helps to balance out the universe, since you helped me so much.
2 Likes