Explaining Local States and Values

Getting started with Touch Portal

This guide will explain what Local States and Values are and how you can use them to improve your flows.

Local vs Global

Values and integration states (Twitch, Photoshop etc) within Touch Portal are global in nature. This means that within Touch Portal there is only one state. This is different for local states and Values. They are bound only to the flow they are part of. This comes especially in handy with Events and the states that belong to those events. But it can also greatly reduce the amount of Values you need to create for Value manipulation as you can use the local Values within a flow of actions.

A little bit more detail

Take for example a Twitch Chat Message state. Everytime your receive a new chat message in Twitch, Touch Portal registers this and stores it in a global state. As soon as a new message is received it will store that new message into that global state, overwriting the old state. The upside of this is that you are able to use this state everywhere within Touch Portal to make creative and complex flows and setups to do wonderful stuff for your viewers.

The downside is that you cannot rely on that value when you are using flows that take more time than the time between receiving the first and the second message. This especially becomes clear when you use Global Events with a queue.

This is where local states and Values come into play. These are connected to the flows they are part of. To put it more clearly with the Twitch example, each Event that is triggered when receiving a chat message will have its own set of states that will not change if a new chat message will be received. That will just create a new event flow with the new local states attached.

Here is a small overview image of how the Global states and Local states are related with Chat Messages coming in from Twitch:

As you can see with the global states you cannot rely on them to have the expected value during the full execution time of your flows. Each line originating from an event in the image represents the time of executing the flow of actions that the event triggers. While the first flow was still running, a new message was received. The global state is changed from that moment. Using that in the flow of the first event (which was still running) would have had an unwanted effect. With the local states however, you can see that they will stay the same expected value as long as the flow of actions is running.

Using local states

To show how to use the local states we will show you an example of what we described above but now with an actual flow.

We assume you are aware of how a global Event is set up (if not, check out our guide on the subject first) but we will go through the flow step by step.

  1. The event starts the flow - A chat message comes in that starts with the command !so and triggers our global Event.
  2. Get the shout out user - We use the local state of the Twitch Message in a calculus action to remove the !so part. This will leave us with only the name stored in a local Value. This local Value is only set and available for this instance of the event flow that is executed. Each other instance of the same event (other messages that come in) will have its own local states and Values.
  3. Send a reaction - We are using the local Value now to send a chat message to Twitch.
  4. Wait for 30 seconds - We want to send another message to the same user 30 seconds later. This will also demonstrate that no matter how many other chat messages will come in, during the flow it keeps the local states the same.
  5. Send another reaction - Thirty seconds later we send another message with the same user as the first message.

As you can see you use the same actions you use for global states and Values but you select the local variants when you want to use them locally.

Please note that the states that belong to an Event will only be available in the flow that is triggered by such an Event. For example, the local states for a Twitch Chat Message event will only be available in that flow of actions that is triggered from that Twitch Chat event. The will not be available in other flows.

Using local Values

The previous section already showed a bit about the local Values. With Touch Portal you will have 10 local values to your disposal that you can use locally within a flow of actions. They are bound to that single instance of a running flow.

You can use local Values for requirements that are only needed during the run of a flow, be it triggered by an event, a button press or anything else.

Back to Guide Overview