# Function (LUA) called twice \[SOLVED\]

**URL:** https://forum.electra.one/t/function-lua-called-twice-solved/1105
**Category:** Bug reports
**Created:** [November 20, 2021, 12:02pm UTC](https://forum.electra.one/t/function-lua-called-twice-solved/1105 "2021-11-20T12:02:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)
#### Post date: [November 20, 2021, 12:02pm UTC](https://forum.electra.one/t/function-lua-called-twice-solved/1105/1 "2021-11-20T12:02:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)
#### Post date: [November 22, 2021, 3:39pm UTC](https://forum.electra.one/t/function-lua-called-twice-solved/1105/2 "2021-11-22T15:39:56Z")

</div>

> [@oldgearguy](#):
>
> **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.

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?

---

<div class="post-metadata">

### Author: ![oldgearguy](https://avatars.discourse-cdn.com/v4/letter/o/f4b2a3/32.png) [@oldgearguy](https://forum.electra.one/u/oldgearguy)
#### Post date: [November 22, 2021, 3:46pm UTC](https://forum.electra.one/t/function-lua-called-twice-solved/1105/3 "2021-11-22T15:46:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![martin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/martin/32/145_2.png) [@martin](https://forum.electra.one/u/martin)
#### Post date: [November 25, 2021, 10:47pm UTC](https://forum.electra.one/t/function-lua-called-twice-solved/1105/4 "2021-11-25T22:47:21Z")

</div>

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