Halion Script Math Limitation?

I am trying to create a parameter from the Sample Rate Reduction parameter of in the distortion audio FX. By default it goes from 20hz to 96000hz. I want my created parameter to instead to go from 0 to 100. I also want it to move in reverse so that 0 = 96000hz and 100 = 20hz. In order to do that I wrote this code that I am pretty sure is right but Halion doesn’t seem to respond to it and I assume it’s because the numbers I am using are too large. Anyone able to help with this?

bus = this.parent:getBus("Internal FX")

if bus then
    effect2 = bus:getEffect("Distortion")
    if effect2 then
        function onSampleCrushChange()
            effect2:setParameter(3, 96000-SampleCrush*.00096)
        end
        defineParameter("SampleCrush", "SampleCrush", 0, 0, 100, 1, onSampleCrushChange)
    end
end

You could try that with setParameterNormalized, which is using normalized range from 0 to 1.

As your parameter has range from 0 to 100, it should be easier to calculate. Just divide by 100 and you get the range needed for setParameterNormalized. To invert the range subtract the range from 1.

bus = this.parent:getBus("Internal FX")

if bus then
    effect2 = bus:getEffect("Distortion")
    if effect2 then
        function onSampleCrushChange()
            effect2:setParameterNormalized(3, 1-SampleCrush/100)
        end
        defineParameter("SampleCrush", "SampleCrush", 0, 0, 100, 1, onSampleCrushChange)
    end
end

Another thing to think about is that the Rate parameter has a range of 20 to 96000Hz but the range is not linear. If you connect a knob to it and you get about halfway it has a value about 1400Hz (not 48000Hz).

This might be another reason to use the setParameterNormalized because it will keep the behaviour (curve) of the parameter you want to control. So when you get halfway it will have the same value as if connected directly.

I had no idea you could just normalize a parameter while setting it. That’s a very useful thing to know now. I will use it for now on. There’s a few places where it would’ve been helpful in my code to have known it before lol. I was searching and searching in the lua reference for some sort of math function and it turns out it was built into halion script the entire time. Thanks! Did you just read every function in the developers manual to find this? I’m curious if I’m going about reading the developers manual wrong. Should I just sit down and read it completely from end to end. I usually just read the parts that I feel apply to what I need to do.