keyboard in adding to a slider value

My goal is to have a slider and keyboard inputs updating a float variable. who doesn’t want an excessive number of ways to change a variable at run-time?
It seemed most reasonable to have a local variable which the slider and the keyboard could change. Despite Matt Ragan’s excellent tutorial on the subject (and this of course reflects on my abilities to understand rather than his to demonstrate), i could never get a reference to the variable in a CHOP or TOP to update dynamically.
So, then i tried having the keyboard change the slider value directly. I tried two different approaches to this. Neither produced errors, but neither worked.
See the attached toe file
sliders&keyboards&variables.toe (9.45 KB)

Hey Swampmonster,

I think you’re issue here is your reference in your local variables. You want:

op('../UI/levelsSlider/out1')['Value1']

not

op('../UI/levelsSlider/out1')['v1']

Give that a try to see if that gets your slider → local var update working.

I had to dig into that UI element to find the value that was actually changing when moving the slider. :slight_smile:

thanks Matt. that worked. the ‘v1’ was probably the result of following your tutorial too closely.
one problem down…

Hey swampmonster,

Take a look at this:

[code]increment = 0.01

def offToOn(channel, sampleIndex, val, prev):
v = op(‘UI/levelsSlider’).par.Value1
fieldValue = op(‘UI/levelsSlider/field/string’)

if channel.index == 0:
	v -= increment
	
elif channel.index == 1:
	v += increment

fieldValue[0,0] = v

return

[/code]

Setting a variable to re-use as your increment will save you some headache if you want to change it in the future (and want it to be the same either up or down).

You also don’t need to type your variable (v) again if you don’t want to, and can just use += or -=.

While you can point your variable filedValue directly to the cell, I don’t usually like doing this as it tends to be a little too granular for my taste. Instead I usually define the entire object and then dive into the granularity of it’s use further down the line. Hopefully that helps you get a little closer.

Happy programming!