No internet connection
  1. Home
  2. How to

Is there a way to make a String array work with this script?

By Owen Granich-Young @Owen_Granich_Young
    2021-12-09 18:04:56.197Z

    Hey @raphaelsepulveda and @Chris_Shaw , I have taken your awesome script from here : Create new tracks and rename it with soundflow prompt typing manually and selecting words from a predefined lists and adpated it to make Loop Group cues. It's AWESOME! But now of course I want more. I'd like to have the user define String[] for certain groups. (Mainly for diffrent shows or movies if there's a recurring location.)

    Unfortunatley when I try the below code it kicks back the following error on the second choice where the String[] is.

    const locationNames = event.props.locationNames
    
    ///Naming function
    const trackNameItems = {
        instrument: [
            "<NONE>",
            "Ext Day",
            "Ext Night",
            "Int Day",
            "Int Night",
            "ENTER NAME",
        ],
        location: [
            "ENTER NAME",
            "<NONE>",
            locationNames,
    
        ]
        section: [
            "<NONE>",
            "ENTER NAME",
            "Beds",
            "Bys",
            "Callouts",
            "Laughs",
            "Claps",
            "Breath",
            "Fight Efforts",
        ],
        suffix: [
            "<NONE>",
            "ENTER NAME",
            "[R3]",
            "Specific",
    
        ]
    }
    
    var selectedTrackNameItems = []
    
    // Enter / select track name items
    for (const i in trackNameItems) {
        var selectedNameItem = sf.interaction.popupSearch({
           title: `Select/Search/Enter ${i} name`,
            items: trackNameItems[i].map(item => ({ name: item })),
            onCancel: 'Abort',
        }).item.name;
    
        if (selectedNameItem == "<NONE>") selectedNameItem = "";
    
        if (selectedNameItem == "ENTER NAME") {
            selectedNameItem = sf.interaction.displayDialog({
                title: `Name ${i}`,
                prompt: `Enter ${i} name`,
                defaultAnswer: `<${i}>`,
                buttons: ["Cancel", "OK"],
                defaultButton: "OK",
            }).text
        };
        selectedTrackNameItems.push(selectedNameItem)
    };
    
    // Join all selectedTrackNameItems to create newTrackName
    var newTrackName = selectedTrackNameItems.join(" ")
    
    log(newTrackName)
    

    Is there a workaround?

    Bests,
    Owen

    Solved in post #29, click to view
    • 30 replies

    There are 30 replies. Estimated reading time: 16 minutes

    1. Chris Shaw @Chris_Shaw2021-12-09 18:18:28.820Z2021-12-09 18:29:36.178Z

      You were missing a comma after the location: end bracket.

      You need to combine the event.props array with an array of default script choices using the .concat() method shown below:

      const userLocationNames = ["Bedroom", "Garage"] //substitute this with your event.props
      
      const defaultLocations = ["ENTER NAME", "<NONE>"]
      
      //Combine user names with default names
      const locationChoices = defaultLocations.concat(userLocationNames)
      
      ///Naming function
      const trackNameItems = {
          instrument: [
              "<NONE>",
              "Ext Day",
              "Ext Night",
              "Int Day",
              "Int Night",
              "ENTER NAME",
          ],
          location: locationChoices,
          section: [
              "<NONE>",
              "ENTER NAME",
              "Beds",
              "Bys",
              "Callouts",
              "Laughs",
              "Claps",
              "Breath",
              "Fight Efforts",
          ],
          suffix: [
              "<NONE>",
              "ENTER NAME",
              "[R3]",
              "Specific",
      
          ]
      }
      
      var selectedTrackNameItems = []
      
      // Enter / select track name items
      for (const i in trackNameItems) {
          var selectedNameItem = sf.interaction.popupSearch({
              title: `Select/Search/Enter ${i} name`,
              items: trackNameItems[i].map(item => ({ name: item })),
              onCancel: 'Abort',
          }).item.name;
      
          if (selectedNameItem == "<NONE>") selectedNameItem = "";
      
          if (selectedNameItem == "ENTER NAME") {
              selectedNameItem = sf.interaction.displayDialog({
                  title: `Name ${i}`,
                  prompt: `Enter ${i} name`,
                  defaultAnswer: `<${i}>`,
                  buttons: ["Cancel", "OK"],
                  defaultButton: "OK",
              }).text
          };
          selectedTrackNameItems.push(selectedNameItem)
      };
      
      // Join all selectedTrackNameItems to create newTrackName
      var newTrackName = selectedTrackNameItems.join(" ")
      
      log(newTrackName)
      
      1. Using this method you could customize all of the naming choices with templates and event.props

        1. Yep already thinking now I should problably just do that 😂

          1. 😃😃😃
        2. In reply toChris_Shaw:

          Doh!

          Thanks man! Perfection as always!

          bests,
          Owen

          1. In reply toChris_Shaw:

            One more quesiton if you're willing. How would I make it so you can toggle on or off any of the name secitons? So if i didn't need suffix I could have it templated to toggle off and have one less menu to jump through?

            1. I'll have this for you in a bit.
              Having a computer problem at the moment.

              1. Bruh take all the time you need, you are a boss!

                1. it will require very specific naming of the template props to work.

                  1. Current props names

                    const userPrefix = event.props.prefixText
                    const userlocationNames = event.props.locationNames
                    const useractionText = event.props.actionText
                    const usersuffixText = event.props.suffixText
                    const defaultChoices = ["ENTER NAME", "<NONE>"]
                    const prefixChoices = defaultChoices.concat(userPrefix)
                    const locationChoices = defaultChoices.concat(userlocationNames)
                    const actionChoices = defaultChoices.concat(useractionText)
                    const suffixChoices = defaultChoices.concat(usersuffixText)
                    
                    1. In reply toChris_Shaw:
                      Chris Shaw @Chris_Shaw2021-12-09 20:17:50.999Z2021-12-09 20:40:01.634Z

                      To make presets that skips naming steps you need to create booleans in your template whose property names begin with the names of the properties in trackNameItems like so:

                      instrumentNamingSkip
                      locationNamingSkip
                      sectionNamingSkip
                      suffixNamingSkip

                      Which will give you a preset that looks something like this:

                      In the for (const i in trackNameItems) loop, i returns the current name of the property in trackNameItems.

                      The next line of code combines the property name with "NamingSkip" which in turn will return the event.prop with that combined name (ex. sectionNamingSkip). If that returns returns false then that naming step will be skipped:

                      if (event.props[i + "NamingSkip"] != false)

                      Here's the new code:

                      const userLocationNames = ["Bedroom", "Garage"] //substitute this with your event.props
                      
                      
                      const defaultLocations = ["ENTER NAME", "<NONE>"]
                      
                      //Combine user names with default names
                      const locationChoices = defaultLocations.concat(userLocationNames)
                      
                      ///Naming function
                      const trackNameItems = {
                          instrument: [
                              "<NONE>",
                              "Ext Day",
                              "Ext Night",
                              "Int Day",
                              "Int Night",
                              "ENTER NAME",
                          ],
                          location: locationChoices,
                          section: [
                              "<NONE>",
                              "ENTER NAME",
                              "Beds",
                              "Bys",
                              "Callouts",
                              "Laughs",
                              "Claps",
                              "Breath",
                              "Fight Efforts",
                          ],
                          suffix: [
                              "<NONE>",
                              "ENTER NAME",
                              "[R3]",
                              "Specific",
                      
                          ]
                      }
                      
                      var selectedTrackNameItems = []
                      
                      // Enter / select track name items
                      for (const i in trackNameItems) {
                          if (event.props[i + "NamingSkip"] == false) {
                              var selectedNameItem = sf.interaction.popupSearch({
                                  title: `Select/Search/Enter ${i} name`,
                                  items: trackNameItems[i].map(item => ({ name: item })),
                                  onCancel: 'Abort',
                              }).item.name;
                      
                              if (selectedNameItem == "<NONE>") selectedNameItem = "";
                      
                              if (selectedNameItem == "ENTER NAME") {
                                  selectedNameItem = sf.interaction.displayDialog({
                                      title: `Name ${i}`,
                                      prompt: `Enter ${i} name`,
                                      defaultAnswer: `<${i}>`,
                                      buttons: ["Cancel", "OK"],
                                      defaultButton: "OK",
                                  }).text
                              };
                              selectedTrackNameItems.push(selectedNameItem)
                          }
                      };
                      
                      // Join all selectedTrackNameItems to create newTrackName
                      var newTrackName = selectedTrackNameItems.join(" ")
                      
                      log(newTrackName)
                      
                      
                      1. 🤯🤯🤯 Oh man what waters have I wandered into. Thanks for spelling it out gonna give it a try!

                        1. So if I'm reading correclty the Boolean's need to reference these names exaclty correct?

                          IE: prefix | location | action | suffix

                          1. or to be EXACT :

                            prefixNamingSkip
                            locationNamingSkip
                            actionNamingSkip
                            suffixNamingSkip
                            
                            1. Chris Shaw @Chris_Shaw2021-12-09 20:33:35.113Z2021-12-09 20:47:39.813Z

                              .

                            2. Chris Shaw @Chris_Shaw2021-12-09 20:32:55.233Z2021-12-09 20:46:40.990Z

                              [EDIT: ignore this as wel!!]
                              In your case the booleans should be named:
                              prefixNamingSkip
                              locationChoicesNamingSkip
                              actionNamingSkip
                              suffixNamingSkip

                              1. Why the one locationChoicesNamingSkip is Choices and the others are not in your list? Sorry if it's obvious...

                                The other's then shouldn't be

                                prefixChoicesNamingSkip
                                actionChoicesNamingSkip 
                                suffixChoicesNamingSkip 
                                
                                1. My bad (again 🤦‍♂️)

                                  it should be
                                  prefixNamingChoicesSkip
                                  locationChoicesNamingSkip
                                  actionChoicesNamingSkip
                                  suffixChoicesNamingSkip

                                  (That'll teach me not code before three cups of coffee)

                                  1. It actually worked the other way instead interstingly enough. The locationChoicesNamingSkip did not work but the other 3 did so I swapped that one to match the others and it was good.

                                    🤷🏽‍♂️🤷🏽‍♂️🤷🏽‍♂️

                          2. In reply toChris_Shaw:

                            Oops! some of the pics were displaying the incorrect names.
                            Corrected now

                            1. In reply toChris_Shaw:
                              Chris Shaw @Chris_Shaw2021-12-09 20:29:15.632Z2021-12-09 20:41:27.178Z

                              [ EDIT: IGNORE THIS!!!!! ]

                              if (event.props[i + "NamingSkip"] != false)
                              could also be rewritten as
                              (if (event.props[i + "NamingSkip"])

                              1. Does it matter one way or the other?

                                1. 🤦‍♂️🤦‍♂️🤦‍♂️
                                  Ughhh!
                                  It does!
                                  My bad.

                                  Also the code isn't quite right I've posted the new code above

                                  1. Hopefully that should be the end of my mistakes 🤣

                                    1. In reply toChris_Shaw:

                                      hahah I'm getting that! They're inverted right now! LOL checking above code. And I figured out above note too, location one should match the others!

                                      1. Be sure to post you completed code when you got it working. The above thread will be confusing to follow :)

                                        1. (no thanks to me 🤪)

                                          1. yYou might want to consider renaming action: useractionText
                                            to action: actionChoices for consistency

                                            1. Oh yeah And I messed up too! That one doesn't have the combined correct!

                                          2. In reply toChris_Shaw:
                                            OOwen Granich-Young @Owen_Granich_Young
                                              2021-12-09 21:03:11.863Z2021-12-09 21:27:10.317Z

                                              It's all working!

                                              Final code :

                                              const userPrefix = event.props.prefixText
                                              const userlocationNames = event.props.locationNames
                                              const useractionText = event.props.actionText
                                              const usersuffixText = event.props.suffixText
                                              const defaultChoices = ["ENTER NAME", "<NONE>"]
                                              const prefixChoices = defaultChoices.concat(userPrefix)
                                              const locationChoices = defaultChoices.concat(userlocationNames)
                                              const actionChoices = defaultChoices.concat(useractionText)
                                              const suffixChoices = defaultChoices.concat(usersuffixText)
                                              ///const suffixToggle = false
                                              
                                              ///Naming function
                                              const trackNameItems = {
                                                  prefix: prefixChoices,
                                                  location: locationChoices,
                                                  action: actionChoices,
                                                  suffix: suffixChoices,
                                              }
                                              
                                              var selectedTrackNameItems = []
                                              
                                              // Enter / select track name items
                                              for (const i in trackNameItems) {
                                                  if (event.props[i + "NamingSkip"] == false) {
                                                      var selectedNameItem = sf.interaction.popupSearch({
                                                          title: `Select/Search/Enter ${i} name`,
                                                          items: trackNameItems[i].map(item => ({ name: item })),
                                                          onCancel: 'Abort',
                                                      }).item.name;
                                              
                                                      if (selectedNameItem == "<NONE>") selectedNameItem = "";
                                              
                                                      if (selectedNameItem == "ENTER NAME") {
                                                          selectedNameItem = sf.interaction.displayDialog({
                                                              title: `Name ${i}`,
                                                              prompt: `Enter ${i} name`,
                                                              defaultAnswer: `<${i}>`,
                                                              buttons: ["Cancel", "OK"],
                                                              defaultButton: "OK",
                                                          }).text
                                                      };
                                                      selectedTrackNameItems.push(selectedNameItem)
                                                  }
                                              };
                                              
                                              // Join all selectedTrackNameItems to create newTrackName
                                              var newTrackName = selectedTrackNameItems.join(" ")
                                              
                                              log(newTrackName)
                                              

                                              Final Boleans:

                                              I then use this to create Region groups for group cuing, full package in the store 'ADR CUE Creator'

                                              Thanks for all your help Chris!

                                              Of course I've gotten one more idea into my head to have the option of a FIXED text for any field as yet a third option... (very useful if it's one character you're cuing FS for for example, over a series of changing surfaces.) You've already done so much and adding yet another variable seems daunting 😂😂😂... but if you're bored 😃

                                              You are a rockstar bud!

                                              Reply3 LikesSolution