Main Lua script uploaded via SysEx cannot access controls

Background

I’m trying out @Martin’s Electra One API library and command line tools (electraone-cli). However, the issue I’m having probably has to do with the SysEx that electraone-cli sends.

Objective

I’m trying to update the current preset’s main Lua script (main.lua) from a file on my PC. If it works, that would save me having to copy and paste the script, which I edit in an IDE, into the E1 web editor and send the preset to the E1.

Method

I run an electraone-cli command similar this:

electraone --in-port-index 2 --out-port-index 3 lua upload "D:\\My Preset\\My Script.lua"

I believe that sends the Upload Lua script SysEx message, something like this:

0xF0 0x00 0x21 0x45 0x01 0x0C script-source-code 0xF7

Problem

The problem is that, though the preset can call functions in the script, such as when the user pushes a button, the script cannot access data in the controls. Each attempt to do so fails with a logged error message. Here are two control access examples.

local controlValue = ctrl:getValue("value")
ctrl:setName("Transpose Off")

In both cases, the error message looks similar to this:

Log: error running function 'onAfterTouchPoly': ctrlv2/slots/b00/p03/main.lua:1139: attempt to index a nil value (local 'ctrl')

Discussion

I expect the cause of the problem is that I’ve only updated the Lua script, not the whole preset. It seems that, when that happens, the replacement preset has no bindings to the control data.

What can I do about this? One option that I expect would work would be for me to write some code to merge the amended Lua script into the preset file. Then I would send the preset file instead of the Lua file to the E1, which can be done with an electraone-cli command or a SysEx message.

Are there easier ways? Preferably via electraone-cli, though I could write my own code with SysExes.

I will take a look at it and will let you know.

1 Like