Local Variables, Modules and Storage — Tip in TouchDesigner#4
How to store data by Local Variable, Modules and Storage.
Thanks Teacher Ragan make a very clear video to teach us how to use Local Variables, Modules and Storage.
If you prefer a video tutorial, clicking the link below.
https://matthewragan.com/2015/03/29/thp-494-598-modules-local-variables-and-storage-touchdesigner/
Ok, if you are ready for text version tutorial.
Let’s dive into it.
Introduce the keywords
First of all, we have to know there’re some keywords in TouchDesigner.
Operator names :
- local
- variables (inside the local)
- modules (inside the local)
Scripts
- var
- mod
- store()
- fetch()
Don’t panic. We’ll talk more detail about each of them.
Local Variables
There’s a way to use Local Variables. (It’s almost like global variable, if you create at the top scope.)
Steps :
- Create a Base (COMP op), and rename it with “local”.
- Inside the “local”, create a Null (DAT op), and also rename it with “variables”.
- Create a Table (DAT op), and connect with “variables”.
Done !
How to use it ? Just type this script.
me.var('your_var_name')
Even you can use it with routes of CHOP or Slider… etc.
Modules
There’s a different way to achieve storing.
The more powerful thing is it can store FUNCTION as well.
Steps :
- Create a Base (COMP op), and rename it with “local”. (Same 1 step with Local Variables)
- Inside the “local”, create a Base (COMP op), and also rename it with “modules”.
- Inside the “modules”, create a Text (DAT op) and you can also change the name if you want. (It’ll make the modules more clear.)
- Inside the Text
Done !!
The script for using.
me.mod.TEXT_OP_Name.VARIABLE_Name
In this example, our script is
me.mod.CHOPs.LFO
Even if you use multiple channels in the CHOP operator.
You can create another Text (DAT op) for storing channel names.
Even more, you can store FUNCTION here.
Storage
The third way is Storage.
It’s more like normal variable of coding language.
- Use “store()” function to store data.
- Use “fetch()” function to get data.
- Use “unstore()” function to remove data.
Scripts :
me.parent().store(‘the_target_data’) # Store the datame.parent().fetch(‘the_target_data’) # Get the datame.parent().unstore(‘the_target_data’) # Unstore the data.me.parent().unstore(‘*’) # Unstore everything.
Pretty simple, right?
Of course, you can store CHOPs data. Or SOPs data is fine.
If you add the ‘channel name’, it’ll get each value in the CHOP op.
Even more, you can create a python dictionary. It’s easier to use.
By the way, all scripts will automatically update. It means real time update.
-
Yeah, that’s all.
I think the 3 ways are very important.
Practice more and enjoy programming !!
References:
https://matthewragan.com/2015/03/29/thp-494-598-modules-local-variables-and-storage-touchdesigner/