MIDI IN Block Script Inadvertently Remapping Channels

Ok, I’m stumped. Can someone point out what I’m missing here?

I wrote a script to toggle the first 5 channels of a MIDI IN block on/off with a button. The toggle is behaving as expected. However, when I toggle them back on, it switches the output channel to 16. If I toggle them manually inside of the plugin window, they are mapped one-to-one like default.

Your insight is greatly appreciated, as always!

var analogV1, edrumin: PluginBlock
var label1,button1 : Widget
var i : Integer

on WidgetValueChanged(newvalue: double) from button1
SetWidgetLabel(label1, GetPluginCaption(analogV1))
    if newvalue == 1.0 then
        For i = 0; i < 6; i = i + 1 Do
        SetParameter(edrumin, i, 0.0)
        end
    elsif newvalue == 0.0 then
        For i = 0; i < 6; i = i + 1 Do
        SetParameter(edrumin, i, 1.0)
        end
    end
end

2022-06-27 21.45.25

Widget values go from 0.0 to 1.0 as do all host automation parameters. Hence for a channel parameter, 1.0 represents the last value, i.e. channel 16 and 0.0 represent the first value, which is OFF. So all the other channels are fractional values between 0.0 and 1.0

Duly noted. This is my first experimentation with directly setting parameters via script, so I will apply this newfound knowledge moving forward. Thanks @dhj :pray: