No internet connection
  1. Home
  2. How to

Question: How to pull variables from a surface for use in a script?

By Eric Huergo @Eric_Huergo
    2021-10-25 21:28:58.122Z

    Hey everyone, sorry to keep bugging with questions (I promise I'm looking as hard as I can but I'm still hitting roadblocks! I'll get there I promise!!!).

    Anyhow, essentially I'm making a package with surfaces for use with Pro Tools. My aim is for whoever decides to use it to be able to hit a key command, a button on the stream deck, etc... and pull up the first of a few surfaces which after inputting data, should take them to the next one and so forth before finally running the script with the variables that the user typed in.

    The first surface is very simple. It prompts the user with a blank text field and asks something like "what would you like to call this group of tracks?". My aim is for the user to type something like "Guitars", click the "OK" button and then have the script log the data under a variable like 'nameOfTracks', close that surface and open up the next one for more input.

    If I can figure out how to do that I feel like I might be able to make the rest of it work but I've been searching far and wide for info on scripting surfaces and unfortunately as of now it seems a bit limited. Hopefully if someone can help me answer this it'll help someone else farther down the line!

    Many thanks for all the support, seriously loving SoundFlow and the community here!
    Best, Eric.

    Solved in post #2, click to view
    • 8 replies
    1. Kitch Membery @Kitch2021-10-26 00:11:42.108Z

      Hi @Eric_Huergo,

      If you have not already seen it, for more information on how to build and design your own Surfaces, please take a look at this webinar:

      https://www.facebook.com/watch/?v=2794860320623955

      As far as storing variables that can be used across multiple commands. You can use globalState for this.

      To assign a value to a globalState variable just do this.

      globalState.myVariable = "My Value";
      

      Then from any other script you can read or use the state as follows (In this example we are just logging the variable that was assigned to the variable)

      log(globalState.myVariable);
      

      I hope that helps.

      Reply2 LikesSolution
      1. In reply toEric_Huergo:

        Eric,

        Another good way to do this, if you just need simple user input, is to use prompt, for example:

        let songName = prompt(`Please enter the song name`);
        
        let albumName = prompt(`Please enter the album name`);
        
        alert(`Alright, let's make the song "${songName}" for the album "${albumName}"`);
        
        1. In reply toEric_Huergo:
          Eric Huergo @Eric_Huergo
            2021-10-27 02:53:54.227Z

            @Kitch - I saw the webinar and am definitely excited to get going on some Surfaces but thank you for clearing up globalState for me, it certainly helps although I did find an alternate solution for my particular problem!

            @chrscheuer - Really appreciate this, will definitely be using this in the near future!

            Thank you both so much for all the support!!! :)

            1. Kitch Membery @Kitch2021-10-27 02:55:13.500Z

              Great to hear @Eric_Huergo :-)

              Rock on!

              1. In reply toEric_Huergo:
                AAndrew Sherman @Andrew_Sherman
                  2021-10-27 08:55:57.024Z

                  Hi Eric,

                  There's another alternative to Global state which can also be useful; I sometimes use a .json file saved to hard drive which can store variables. These variables remain saved/stored even when restarting. Save a variable to a file on the hard drive until it needs to change again #post-17

                  1. Eric Huergo @Eric_Huergo
                      2021-10-27 18:38:52.746Z

                      Andrew, I'd actually checked out that thread before out of curiousity and not just yet but I think that at some point in the near future this might prove to be really useful so thank you for looking out!! :)

                      1. AAndrew Sherman @Andrew_Sherman
                          2021-10-27 20:33:33.576Z

                          No worries - and just to be clear anything from Christian or Kitch would be the recommended approach!

                          1. Kitch Membery @Kitch2021-10-27 20:45:26.426Z

                            Nice one @Andrew_Sherman!

                            Your suggestion is also totally valid, and a great approach if you need the variables to persist. :-)