If statements

Hi there. I’m new to Touchdesigner so some things I know how to program but not how I would specify this in TouchDesigner.

I find myself wanting to use an if statement, is this possible in touch designer? I have a count which counts from 1 to 7. I would like to link this to 7 separate null nodes which each hold a value of 0 and 1.

When count is on each nodes representative number the null node should contain a value of 1 signalling it is on, if it is not being referenced then it should show 0 representing it is off.

Hope I explained this clearly enough

Could someone give me a simple example of an if statement working on values of nodes within a system? If I had this i’m sure id be able to work it out myself but they’re arent any on the wiki

Hello Matty10209,

The wiki will be your best companion while working with TD
derivative.ca/wiki077/index. … Statements

hey ab30

Thanks for replying, but i’ve read this back to front now. I just asked because i’ve been through most of the tutorials and none of them seem to have discussed Tscript at length or given examples of using data within nodes.

If ive overlooked anything please feel free to correct me

Ok, sorry. With CHOPS, here an example of how to do that, if I correctly understood what you meaned.

PS: this is a 088 file, but it loads without conflict in 077, so you can pass the warning prompt if on 077.
COUNT_AND_EXPRESSION.tox (1.7 KB)

Ah! This is how count is used! I knew there must have been a simpler way! I remember being confused because the left input on the node says “channels to count” so i put in a math chop with the corresponding numbers. I just put a simple square wave in on the left as I want it to play automatically and it goes through them fine.

I had no idea you could use count as kind of an opposite to the switch by connecting more than one node on the right. This should be made clearer in the wiki.

Thanks a bunch

This is done thanks to the expression CHOP: if you look closely onto the parameters of each chop, you will find a conditional expression:

``if(\$V=\$index,1,0)``

and you could do that more easily with the operator digit variable:

``if(\$V=\$OD,1,0)``

countExpressonPY.tox (8.6 KB)

sorry about reviving a very old thread, but here is an updated version with python instead of tscript in the examples in case anyone needs it in the future.

1 Like

Hey @JasonZeh,

another good operator to look at for this is the Fan CHOP. It will take channels with index values as input and set the channel of the input index to 1. So if the input value is `1`, then the second channel in the Fan CHOP will be set to 1 (TouchDesigner is zero based)

cheers
Markus

1 Like