No internet connection
  1. Home
  2. How to

Question: Syntax doubts with if/then?

By Eric Huergo @Eric_Huergo
    2021-10-27 21:40:38.488Z2021-10-27 22:55:36.226Z

    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!

    Solved in post #2, click to view
    • 2 replies
    1. 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 to isSetColorOfAudioTracksToNone.

      Hope that helps you on your scripting journey. You got this!

      ReplySolution
      1. Eric Huergo @Eric_Huergo
          2021-10-28 02:29:51.325Z

          @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