# How to change a value based on two inputs

Hi,

im new to Touchdesigner and I would like to do the following action. I have a generated Object and I want to change the offset value of this object to exactly 10 if someone is moving too fast. if the offset is at 10 you can reset it to 0 with a touch input. The Speed input comes in from an Arduino in a range from 0-100 (too fast would be >20 for example). The touch input is simply a 0 or 1 (no touch =0, touch = 1). How can I build this situation exactly (what nodes and what expressions do I need in which order?)? In the picture you can see the current state - I have both of my inputs as CHOP and try to fire a 1 with expressions to a count. is this right?

These are my two expressions which im using right now:

1 if op(‘Speed’) >= 5 and op(‘offset’) == 0 else 0
1 if op(‘touch’) == 1 and op(‘offset’) == 10 else

0

the count should simply loop between min and max (it was an template which changes the value between 0 and 1 up and down every time I pressed the key 1) - just for explanation. I tried to compare the last node (offset) in the expression but right now the values are doing nothing…

Hello,
– Its easier to help if you publish your project.
– Its sometime easier to use some lines of Python oposed to link Chop operators…

Hi - thank you for your time! sure here is the current file
Dynamic_Shape_sensors.toe (23.8 KB)

if I see it right it would be enough to give out the value 1 each time one of the condition ist fulfilled (the count simple changes then the value between 0 and 10) right? its just important to check the current offset somehow and compare It with the current values…

so sth like this but how can I achieve it via script?

1 if op(‘Speed’) >= 5 and op(‘offset’) == 0 else 0
1 if op(‘touch’) == 1 and op(‘offset’) == 10 else

Your goal its not very easy to understand…
I see not only 2 variables but three variables (speed, touch and offset).
I tried to make sense of your question:

``````def onValueChange(channel, sampleIndex, val, prev):
speed = op('merge1')['speed']
touch = op('merge1')['touch']
offset = op('offset')['offset']
expression = 0
if (speed >= 5) and (offset == 0):
expression = 1
else:
expression = 0
if (touch == 1) and (offset == 10):
expression = 1
else:
expression = 0
print(expression)
op('expression').par.value0 = expression
return
``````

changeValue.toe (5.5 KB)

Thank you very much for your effort! I think I’ve found what im looking for with this example. Thanks to Chat GPT I’ve modified the script with two more conditions and now its working in my eyes - I think this will do the job

Thanks and kind Regards!

hi @johannesneff how were you able to reference the CHOP value to modify the object?

You original question is being answered here:

cheers
Markus