Beginner: Global Variables

Global variables are a powerful tool to use not only in conjunction with Fologram AR applications, but with in grasshopper in general. Global Variables allow the storage and updating of data inside a grasshopper definition. This gives control over variables used on repeat in a grasshopper definition, and makes updating these variables to easy.

Using Global Variables
There are two global variable components: ‘Get Global Variable’ and ‘Set Global Variable’. Globals are linked together by their name, so any global with the same name as another will store the same data. They have a non-specific with type, which means all data types (Curves, Meshes, Text, Colours etc) can be stored inside them. To pass on data from a ‘Set Global Variable’ to a ‘Get Global Variable’ , input a data type (in this example a mesh). A circular arrow will appear on the ‘Get Global Variable’ component. Click on this and the component will update and store the mesh.

Using a Dynamic Loop
To skip the circular arrow, right click on the ‘Get Global Variable’ and turn on ‘Dynamic Update’. This will automatically push data to the component without the manual prompt.

Using Global Variables in a Loop
Global variables can be used to create data storage loops. In this example, a global is used with a ‘Merge’ component, with the merged result looped back into the global. When the update arrow in the ‘Get Global Variable’ component is pressed, the ‘Set Global Variable’ also updates, creating a recorded loop of the mesh geometry. This is an incredibly useful tool in situations where the mesh geometry is changing or updating during each loop.

Loop Error
Turning on ‘Dynamic Update’ when a ‘Get Global Variable’ and ‘Set Global Variable’ are combined in a loop will throw the error ‘Recursive loop detected, please turn off dynamic updating’. Dynamic updating will cause and infinite loop error and is not possible when the global components are set in a loop together, so avoid turning it on in these scenarios.

Example file:
This example file uses the ‘Set Global Variable’ and ‘Get Global Variable’ in a loop, with a ‘Set Global Variable’ used at the beginning to empty the container.
1.21 (5.2 KB)

1 Like