Can I use ternary operators in Hollywood?

Find quick help here to get you started with Hollywood
Post Reply
SpawnPPC
Posts: 61
Joined: Fri Mar 15, 2024 11:51 pm

Can I use ternary operators in Hollywood?

Post 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
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Can I use ternary operators in Hollywood?

Post by plouf »

Hi

Check out IIf()
Christos
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Can I use ternary operators in Hollywood?

Post 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
SpawnPPC
Posts: 61
Joined: Fri Mar 15, 2024 11:51 pm

Re: Can I use ternary operators in Hollywood?

Post by SpawnPPC »

Thanx for the help !!!

bySpawnPPC
Post Reply