Setting CHOP Channels with Python

Hi everyone,
In my project I’d like to have a Constant CHOP which stores a bunch of states about videos that are playing (“video_playing”, “video_finished”, “video_starting”) in different channels. These channels’ values would be updated from scripts.

However, I’m finding it hard to set the value of Constant CHOP’s channels using python.

I can set them by calling the parameter name of the channel, but this isn’t ideal as it relies on the states staying in their current order:

op("...").par.value0 = 1  # Works! Parameters can be set

I’d rather make changes by calling to the channel name, which is a lot nicer on a few fronts:

op("...")["chan1"] = 1  # Error! Channels don't support assignment

But it doesn’t work. I’ve looked through a lot of the wiki but can’t find any functions that we can call on channels to set their values (or other cool things like pulse() that we can call on parameters). Is there a reason for this? Is setting CHOPs with scripts bad practice? If so, what’s the preferred method? Or have I missed a trick here?

Thanks a lot!
Joe

1 Like

Hi Joe,

this is a wide ranging conceptual question covering multiple topics.

For one, yes, it’s correct, you cannot set channel values for nodes via python except for the Script CHOP. Main reason is that the ability to change channel values would brake the TouchDesigner logic of generators and modifiers. If you would be able to change the channel value of a channel in a Math CHOP, than what effect would the functions of the Math CHOP have and would the value change effect the value before the parameters of the Math CHOP kick in or after.
But again, the Script CHOP is the way around this as it allows to create and modify channels and samples. It’s very unique in that functionality though.

Secondly, often for one idea there are many approaches. When you would like to create something like a state machine you could:

  • store the state in a Table DAT (access state via row name: op(‘table1’)[‘state1’,1] = 1)
  • store the state in storage (ie parent().store(‘state1’,1))
  • utilize the Timer CHOP as a state machine (my favorite, use segments as states and switch through the segments)
  • in the case of the video playback, why not use the info CHOP on Moviefilein TOP, it already gives you the states
  • use radio or exclusive buttons to store the states (op(‘state1’).click())
  • write your own state machine using extensions

and in the coming comments from other users you’ll probably find 10 more praxis approved ways to do this.

Cheers
Markus

1 Like

Awesome reply, thanks Markus. Everything makes a lot of sense.

I’m pretty new to Touch so will just try a bunch of these out and see which suits me, though it seems the table option has the most flexibility (storage looks not as easy to encapsulate, I think).

Thanks again!

Hey,

if you need to convert the Table Data to channels, there is the DATto CHOP.

Cheers
Markus

Thanks for this desciption Markus,

QUick question though’

I am approaching the timer chop and state technique, as it works for a lot of reasons in a lot of ways, however… I am concerned about this techniques cost… the timer chop is “always cooking” and I am unclear as to how that may affect this techniques viability. Is it negligible? should I just go with it… or would a simple table with a row select dat as a state switcher be more optimized?

The Timer CHOP can be fairly expensive - so a system with 10 Timer CHOPs might not be feasible but for most usages it’s added functionality justifies the cost.

As usual, if your needs are much simpler though and the Table DAT setup works, then it is exactly the correct solution.

Cheers
Markus