Hey everyone I'm trying to get a script to select 'None' in the color palette window only if a boolean variable is proven to be true.
Essentially I have a template that establishes a variable through a preset, like so:
var setColorOfAudioTracksToNone = event.props.setColorOfAudioTracksToNone;
My hopes are that if the variable setColorOfAudioTracksToNone is true, then it would run the action when the preset is run. However, if it is false it simply jumps over to the next part of the script. To me this sounds like an if/then statement but I can't for the life of me figure out the proper syntax structure and I'm stuck. Has anybody been able to get something to run conditionally like that before? Even a link to something different but conditional would help!
Thanks once again!!!
Kindest, Eric!
- Raphael Sepulveda @raphaelsepulveda2021-10-28 01:37:28.976Z
Hey Eric,
Yeah! This is pretty standard. You can simply do this:
if (setColorOfAudioTracksToNone) { // Insert code to select "None" here }
So what's happening here is that if the variable
setColorOfAudioTracksToNone
contains a truthy value, then the code inside the block will run. If it's falsy then it'll get skipped altogether.It's common practice to prefix variables that contain a boolean value with
is
, so I'd suggest modifying the name toisSetColorOfAudioTracksToNone
.Hope that helps you on your scripting journey. You got this!
Eric Huergo @Eric_Huergo
@raphaelsepulveda - hahahaha I knew this was super standard but still couldn't manage to figure out the proper order! Needless to say, tried your recommendation and got it to work without a hitch on the first try so thank you very very much for that!
Also, super good tip on identifying booleans with 'is', makes complete sense and definitely taking that with me as well!
Appreciate you and all the help quite a lot!!!!
Un abrazo jefe! <3