LFO Waveform index problem

Using the filtertype code in some of the built-in Halion libraries I created the following code to create new index names for a monophonic LFO waveforms.

--Capitalize all LFO waveform parameters
MidiModule1=this.parent:getMidiModule("LFO 1")
LFO1Waveforms={
  {name="SINE",   index=0},
  {name="TRIANGLE",   index=1},
  {name="SAW",   index=2},
  {name="PULSE",   index=3},
  {name="RAMP",   index=4},
  {name="LOGARITHMIC ",   index=5},
  {name="SAMPLE & HOLD 1",   index=6},
  {name="SAMPLE & HOLD 2",   index=7},
}
 
function getLFO1WaveformNames()
  LFO1WaveformNames={}
  for i=1,#LFO1Waveforms do
    LFO1WaveformNames[i]=LFO1Waveforms[i].name
  end
end

getLFO1WaveformNames()

last = {}

function LFO1WaveformChanged()
  MidiModule1:setParameter(1,LFO1Waveforms[LFO1Waveform].index)
end

defineParameter("LFO1Waveforms",nil,1,LFO1WaveformNames,LFO1WaveformChanged)

The code isn’t working. I’m getting a “Parameter change callback LFO1Waveforms = TRIANGLE: 512: attempt to index global ‘LFO1Waveforms’ (a number value): this.parent:getMidiModule(“LFO 1”):setParameter(1,LFO1Waveforms[LFO1Waveform].index)” error but I’m not sure why. Anyone know what’s wrong here?

Hi abject39,

There are two issues here.

You are using the same name for your parameter and also the table containing the values (LFO1Waveforms).
That’s giving you the error message.

The second issue is just an oversight. In your function you are missing letter “s” ([LFO1Waveform]). Your parameter is called LFO1Waveforms. When the function is called it will be looking for the value of “LFO1Waveform” which will be nil because you didn’t define such parameter or variable and give you another error message.

Once you fix those two things your script should work fine.

--Capitalize all LFO waveform parameters
MidiModule1=this.parent:getMidiModule("LFO 1")
lfo1Waveforms={
  {name="SINE",   index=0},
  {name="TRIANGLE",   index=1},
  {name="SAW",   index=2},
  {name="PULSE",   index=3},
  {name="RAMP",   index=4},
  {name="LOGARITHMIC ",   index=5},
  {name="SAMPLE & HOLD 1",   index=6},
  {name="SAMPLE & HOLD 2",   index=7},
}
 
function getLFO1WaveformNames()
  LFO1WaveformNames={}
  for i=1,#lfo1Waveforms do
    LFO1WaveformNames[i]=lfo1Waveforms[i].name
  end
end

getLFO1WaveformNames()

last = {}

function LFO1WaveformChanged()
  MidiModule1:setParameter(1,lfo1Waveforms[LFO1Waveforms].index)
end

defineParameter("LFO1Waveforms",nil,1,LFO1WaveformNames,LFO1WaveformChanged)

Oh man! How did I miss that lol. The parameter wasn’t supposed to have the S there on the end. I removed it and it all worked!