Saving parameter state when moving a script

Suppose that I have a simple script that processes midi, in this case, a transpose function that has a single parameter which I define in onLoadIntoSlot as follows:

function onLoadIntoSlot()
    defineParameter("Transpose", "Transpose Amount", 12, -96, 96, 1, onTransposeChange)
end

Now, when I move this around the program tree, e.g., above or below another copy of the same script. The value of the parameter is reset as the move is viewed as a new “load into slot.” The built in midi tools, of course, don’t have this issue, if you change a parameter and them move them around, the parameter remains as set.

So, is there some way to preserve state here such that, it defaults to 12 on load, but will remain unchanged when moved around? Are there best practices documented somewhere that I missed? I know that the state is correct immediately on call to onRemoveFromSlot so that seems like the place to preserve the state, but I can’t help but feel like I’m missing something fundamental here.

It would be great to see a good example of a full midi processor written in HalionScript from Steinberg.

Thanks

BTW: I’m new to this forum, not new to Cubase, new to Halion, not new to programming.

Parameters usually aren’t defined inside an Initialisation function like onLoadIntoSlot.

The function call is likely causing the reset, so moving it outside the function will solve this. To apply the state to the new layer/zones you will need a function that uses setParameter. The normal parameter callback is only triggered when a value is physically changed on the UI or parameter list.

The “Transpose” parameter value can also be assigned to another variable for storage.

To have a look at one of Steinberg’s scripts you can load the Mono Step Modulator midi module, select it and open the script editor at the bottom. They left it open so we can have a look inside.