Function (LUA) called twice [SOLVED]

I have a LUA function defined and put it’s name in the JSON to be called when a momentary button is pressed. When I press the button (or turn the encoder associated with it) the function is called correctly.

However, when I release the button (or the knob) the function is called again. Depending on what you are doing in the function call, the effect is either benign or causes problems (sending/receiving sysex for example). In any case, it’s unexpected behavior.

I guess I can code a conditional in the function based on the momentary value, but it might be cleaner to be able to define whether the function is invoked on press, release, (or both I guess if really needed)

EDIT - even weirder - since this is a virtual button, the “value” parameter being passed in is neither 1 nor 0, it’s always nil so I can’t conditionally code a response to the press/release.

EDIT 2 - the documentation states that if an On value or Off value is not defined for a control then the MIDI transmission will be ignored. If that’s the case, then maybe by not defining one state or the other I can get a single MIDI transmission rather than two. I’ll update after testing.

1 Like

I tested that yesterday. It works ok for MIDI messages but the Lua function is fired without regard to the presence of the value.

I am tempted to implement firing of Lua function in the same way as I do that with MIDI messages. Would that work for you?

I write software, I can make anything work. lol

yes, it would be easier if there was a defined way to trigger the call on press/release or on value (or lack of value). Making it work like the MIDI messages would be consistent and easier to keep straight.

Please check firmware 2.1.4, the Lua functions should be called in the same fashion as the MIDI messages are triggered.