Page 1 of 1

Can I use ternary operators in Hollywood?

Posted: Sun Oct 13, 2024 11:11 pm
by SpawnPPC
Hi everyone,

I'm trying to find out if Hollywood supports the use of ternary operators for conditional assignments. Specifically, I'm looking to use a syntax like this:
---
Local variable = condition ? value1 : value2
---
If Hollywood doesn’t support this syntax, are there any recommended alternatives for conditional assignments in a single line?

Thank you for your help!

bySpawnPPC

Re: Can I use ternary operators in Hollywood?

Posted: Mon Oct 14, 2024 7:48 am
by plouf
Hi

Check out IIf()

Re: Can I use ternary operators in Hollywood?

Posted: Mon Oct 14, 2024 7:48 am
by jPV
SpawnPPC wrote: Sun Oct 13, 2024 11:11 pm Local variable = condition ? value1 : value2
Hollywood has the IIf() function which does that:

Code: Select all

Local variable = IIf(condition, value1, value2)
The downside with that is that it evaluates both value1 and value2 before returning the result, so it might be better to not have too heavy calculations in the return values if you use it frequently in loops or so. But for not too time critical things I've used it quite a lot. Handy when constructing some strings or gui elements etc..

Otherwise you might have to search for alternatives done in Lua... like http://lua-users.org/wiki/TernaryOperator

Re: Can I use ternary operators in Hollywood?

Posted: Wed Oct 16, 2024 11:35 pm
by SpawnPPC
Thanx for the help !!!

bySpawnPPC