documentation about setting chop value in python

questions from users about how to set the value in a chop with python keep popping up

op('constant1').par.value0 = insertyourvariablehere

Maybe it should be added a bit more clearly in the documentation. Just searched for it to see if it’s easy to find, and I could not find it on the wiki, only in the forum.

Hey,

it might be a bit misleading to call this “setting” CHOP values where it is in reality changing OP Parameters.
I would be very interested in examples where setting the Constant CHOP value parameters is used. In my opinion writing values to a constant CHOP should be a rather rare occurrence.

Cheers
Markus

Maybe I should be going about a different method of programming, but I’m using a constant chop to store global variables - or event temporary ones. For example, currentScore, highScore, gameState, etc. So I’m constantly doing op(‘constant1’).par.value0 += 1 for the score. So I’m writing values to constant chops frequently. Maybe there’s a better method?

What I’d like is to do is:
score = op(‘constant1’)[‘score’] ( supported )
and set the variable with a simlar method:
op(‘constant1’)[‘score’] = score
instead of
op(‘constant1’).par.value0 = score

Also, is it possible to pass variables to text scripts similar to passing variables in functions, ie,
op('myPythonScript).run(6,myVariable)

Right now, I’m setting these variables in constant chops, so when I call scripts with the run() method, I have access to these variables.

Thanks.

Hi,

Storing values

there are indeed many different ways to store such information, and you are correct, Constant CHOPs are one of the ways to do so. Other possible solutions could be:

  • more clear (read/write) access via row and column labels: op(‘myTable’)[playerID,‘score’]
  • easily attach more information to a value with additional columns
  • easily sortable if necessary without loosing information
  • not CHOPs, need to convert if necessary with a DATto CHOP
  • data is saved as strings so careful when working with it in scripts
  • data is stored as whatever datatype the variable is in (dict, list, int, everything)
  • data can easily be accessed hierarchical: me.fetch(‘score’,None)
  • data is not as visible in the node tree, you kind of need to know where you keep it when storing
  • don’t store data but have it run procedural
    Up to a certain complexity the most optimal way might be to do it all procedural. Python will offer itself up as a great solution but especially CHOPs like Count, Trigger, Timer, Event, Hold and more are tools that often do all the things a developer would have to build into scripts.
    In new projects I try to go as long as I can without typing a line of python code.

Passing values to scripts

you can indeed pass variables as you described:

myVariable = 1 + 1
op('myPythonScript).run(6,myVariable,'someString')

In the script ‘myPythonScript’ all the passed values are accessed via the args list.
So a:

print args

would return:

>>>[6,2,'someString']

Access to each variable therefor can be achieved with regular list syntax.

Hope that helps a bit
Cheers
Markus

That’s great, somehow I just glossed over the run method in the Class pages - teaches me to read documentation better.
And the other options: storage, tables, chops - I’ll need to just see what works best given those options.
Thanks much.

Calvin.

+1 necroing 6yo thread sorry

Some additional info would help noobs like myself if it was consolidated in documentation, such as why can we only set a Constant CHOP’s channel using .par.value0 and not using [n] or [‘name’]

If you do a google search with query "touchdesigner" "value1" you will find nothing in the documentation, as the only thing mentioned about using value0 etc is on TouchDesigner Documentation - Constant CHOP and it’s not really explained

I think I learned about using value0, value1, etc in Constant CHOPs via 3rd party tutorial videos, forum, etc. Maybe I’m missing it somewhere in official docs?

2 Likes