# DAT operations

Hello,
I’m learning touch designer and I try to some simple program but I have problem with something.
I have some table with data, the number of rows is all the time changing and I need to get sum of values in all rows.
Anyone knows how to do that?

hi patucha,

You might do this a couple of different ways.

Here are two different solutions for you. One involves using a for loop to add together the contents of a given row, while the other converts the contents of a row to CHOP channels, and then adds the values together.

Hope this helps.

M

adding 2 more options to Matthews examples:

One is just treating the CHOP data differently by summing up channel samples instead of separate channel values.
The other one is a python equivalent skipping the for loop.

Depending on what else is done with the data, the CHOP version is preferred and usually more optimized.

cheers
Markus

Thanks a lot for help!

I try to do also another thing. Maybe u can also know how to do that too.
I want storage the number of op( ‘count’ )[‘v1’] in moment when op ( ‘limit1’ ) [‘frame’] is equal 600, and save it till op ( ‘limit1’ ) [‘frame’] again will be equal 600 and after that exchange this number with actual value of op( ‘count’ )[‘v1’] in moment when op ( ‘limit1’ ) [‘frame’] is equal 600, and so on and so on

greetings,
Pat
DAToperation2.toe (5.94 KB)

Hi Pat,

the problem you describe can be done with the help of a Hold CHOP.

• first increase the range of you limit1 looping range to 0 - 601, otherwise it will never reach 600
• next instead of scripting the reset pulse of the Count CHOP, use the output of the limit1 CHOP as the second input to the Count CHOP. This is the reset input and in the Count CHOP parameters you can choose when to reset. So for Reset Condition select “While Off”.
• next append a Hold CHOP to the Count CHOP.
• now you need a proper trigger to get the Hold CHOP to sample the value from the Count CHOP. So append a Logic CHOP to the Limit CHOP and select “Off when Outside Bounds” for the Convert Input Parameter and set the Bounds to 600 and 600. This will have the Logic CHOP only have a value of 1 if the incoming channel has the value of 600.
• This Logic CHOP use as the second input to the Hold CHOP and set the Sample Parameter of the Hold CHOP to “Off To On”

A nice small little network without any scripting

Cheers
Markus

Thanks a lot!
Working very well.
Maybe you can recommend some tutorials for beginners about scripting in touchdesigner?
Greetings!

Hi Patucha,
The first scripting samples that came to mind:
raganmd’s Python Lists and Python Dictionaries available on his THP 494 & 598 YouTube channel [url]http://bit.ly/1LBQD0z[/url].

Elburz’ Movie Playlist example available on his Vimeo page. Follow the ‘Click above for the video tutorials’ link on the bottom of his book page http://book.nvoid.com.

Full-on python courses would be the next step but that can get deep pretty quick if you’re new to programming/scripting. Start with these examples and enjoy the ride.

Good luck!
B

Hello all!

was looking for something similar when i stumbled upon this. Wanted to ask how would the approach be if instead of numbers in rows i have text.

Through a code I’m dividing words into separate characters to a table, transposing it so it has only 1 column and rows depending on different words it is being fed over time. I want to count the characters but it seems i need to assign number alongside them so i can later continue with the dat to and then math, add solution matt provided above