# Converting several ranges of values to singular values

Hopefully that title wasn’t too confusing.

I’m familiar with using Math to scale one range of numbers to another range. But what i’d like to do is define several sets of ranges that will convert into singular numbers.

For example:

0 to 50 = 20
50 to 60 = 32
60 to 70 = 25

and so on. So it’s not so much scaling as defining a singular number depending on what range an inputted value would fall into.

What would be the best way of doing this?

Thank you!

if its a simple conditional statement, I’d use a Logic CHOP set to off if outside bounds. If there are multiple ranges, I’d probably use a chop execute with conditional statements. if it were really complex, I’d probably use a lookup chop or lookup table.

here is an example of how you could do this with a chop execute and conditional statements:

``````    if val < 50:
x = 20
elif val >= 50 and val < 60:
x = 32
elif val >= 60 and val <= 70:
x = 25
print(x)
``````

Thank you, that looks like exactly the kind of thing i need.

I’m having some trouble with integrating that into touch though. When I paste that code under the defOnValueChange line in the chopexecute, i have a couple of errors regarding indentation issues and “cannot find function named onvaluechange”.

I’m also not sure how to extract that final value X into a CHOP once that is calculated. Have checked the help file for chopexecute but couldnt see what to do

Have attached an example .toe file

chopexecute.toe (3.5 KB)

here’s a working version.

Python language is indent sensitive - which means you’ll need to indent code under an if function (usually with a tab). This indent needs to be the same all through your code, so no mixing of spaces and tabs, and everywhere the same amount. chopexecute-1.toe (3.6 KB)

Thank you that’s perfect, appreciated