Scripted Knob breaks when changing Sub Presets

I have a knob that controls the amount on a mod matrix row but I scripted it so that it’s limited the range only to 0-100 on the knob. It works great and as expected.

But in this same instrument I have the ability to change between sub presets like you can in Skylab. When I change sub presets, the knob no longer works. If I attach the knob directly to the amount parameter in the mod matrix without limiting the range via script and then switch sub presets it does not break. It works fine. But when it is attached to the script, it no longer works. I’ve attached the code below…am I missing something in it?

allZones=this.parent:getLayer(1):getLayer():getZone()

function onModAmountChange()
  allZones:getModulationMatrixRow(2):setParameter("Destination.Depth", ModAmount2)
end
defineParameter("ModAmount2", "ModAmount2", 50, 0, 100, 1, onModAmountChange)

Thanks!

Have you tried moving allZones inside the callback function.

The zones in the sub preset have different ids and are not the same objects as in the original allZones. So the function is trying to address non existent zones.

function onModAmountChange()
	local allZones = this.parent:getLayer(1):getLayer():getZone()
	allZones:getModulationMatrixRow(2):setParameter("Destination.Depth", ModAmount2)
end

defineParameter("ModAmount2", "ModAmount2", 50, 0, 100, 1, onModAmountChange)

That did it!! Huge thanks to you!

I didn’t realize they would have different ids when changing the subpresets. This is good to know.

Thanks again!