I can't apply my mappings to the device!

I made an encoder element config and have a system element config.
When I try to apply all of them to EN16, after the 8th encoder it starts pouring error messages.
And as storing is done and the device reboots (it doesn’t always happen but it’s happening always now), the errored other 8 encoders haven’t get applied with the change.
When I repeatedly try to apply my config to all elements, sometimes the system element suddenly gets reset.

Here I applied my config to Element 7, then to Element 10. And Element 10 have not changed.

When I clear the entire page and try to reapply all at once, only 12~14 encoders and the system element get changed. Always about 2~4 encoders left unchanged, which is easy spot because changed encoders have their leds going black.

I checked the config file, the same code for an encoder appears 16 times and the system element code is there.

This is frustrating. Is there like a character limit for the whole page and that’s somehow less than the sum of all 400 character limits for each event chain throughout all the elements? I don’t know what’s going on with my config file…

There is no actual character limit for a whole configuration, but huge configs with can sometimes cause trouble when storing.

The error in the Logger is usually a LUA error, check the debug monitor for a longer description.

When you get storing issues like this, I would suggest trying to clear the module fully first and if that doesn’t change the situation, doing a factory reset should properly clear the memory.

If the bug stays even after these steps let me know.

1 Like

Yep, the module after a factory reset still couldn’t load the whole page config.
I wonder what I should do now.

LUA errors happen, but when loading a system config then a single encoder config, they don’t happen anymore after storing the configs to the device.

When I try to load the whole thing, starting from last half of encoders the error starts appearing, but I guess that’s because it only could partially load the config so there must be some references to missing variables created that way.

Can you tell me how big the configuration is? You can find the JSON file in your Editor user directory.
Also, if you can share the config with me, I’ll try it on some modules and try to troubleshoot it that way.

Entire character count is 24,157 and it’s about 23.5KB.
I’ll link the file in my GitHub Gist.

So I’ve found a good amount of problems in your code. Checking the LUA errors could help you out in troubleshooting them, but this is the first problem I found.

The MIDI function expects integers for its parameters, you can’t just send boolean values by themselves.

Also your code used here expects Grid LUA to interpret boolean values of true and false both as boolean values and integers you can do arithmetic with, but that’s just simply not the case, and the LUA error even tells you this.

Your code here: self.cc+(self.hold==1 and ccsh or 0) would add a boolean value (true/false) to an integer and Editor warns you that’s not possible:
image

The LEDs are also not lighting up on my end, but it’s also most probably caused by unfit variables.
Most functions in Grid LUA will only accept proper integers and floats or bools will usually break them.

ccsh is a Global variable setup in Element 16 (system), and it is an integer.
I learned that ternary operator A ? B : C can be executed as A and B or C in Lua, so I wanted the Parameter 1 to be either self.cc+ccsh (both integers) or self.cc.

I guess there was something wrong with this approach then. What would be a better way? :thinking:

We have no implementation for type conversions in our LUA environment. So your best bet is either creating a function that does that e.g.:

function bool_to_integer(bool)
local integer=0
if bool==true then
integer=1
end
return integer

Or using integers as your variables when setting the values you want to send out as MIDI.

As a general rule of thumb:
1, Only do arithmetic and logic in functions that output into variables.
2, Only use variables fit for the function parameters.

You can see the function parameters that they expect on the wiki, e.g.: the midi_send() function.

1 Like

I had no idea there could be things not implemented in the LUA environment! :scream:
So… no ternary operators… I’ll see what I can do without it.

The previous code

midi_send(0, 176, self.cc + (self.hold == 1 and ccsh or 0), val)

is now

local cc = self.cc
if self.hold == 1 then
    cc = cc + ccsh
end
midi_send(0, 176, cc, val)

I hope this time I can apply the whole configuration!

I made it to 14 encoders having the config applied.
Now the error message is simply this:
Failed to register action!

Updated code is reflected to the gist as well.
I want to try applying the first of the general rules and make a function to do the cc + ccsh operation, and see if that helps. But it’s quite late so I will look around it tomorrow.

Thanks for quick and detailed help!

I made a change to put these code in a function, from:

local cc = self.cc
if self.hold == 1 then
    cc = cc + ccsh
end
midi_send(0, 176, cc, val)

to

function add_if_true(c, v, a)
    if c then
        return v + a
    else
        return v
    end
end
midi_send(0, 176, add_if_true(self.hold == 1, cc, ccsh), val)

Still when loading the entire page configuration, about 6 encoders get the changes.
I will revert the change above.

The only meaningful LUA error message I get is this:

The error message ending with “global ‘ccs’” occured when the function cr is inside Setup Event, then when I move it just before the function is actually called (like in the screenshot at Midi rx Event), I get the other message ending with “local ‘ccn’”.

The ‘ccn’ is an argument inside a function, so I don’t get why the error happens.

Now I am getting ‘not enough memory’ on the debug text. Whole page randomly reset when trying to apply changes.

Could it be that the error here is caused by the comment? Please check the code without the comment.

You also have to properly init your variables and functions. There is an order to how Grid intializes, and it’s as follows:

  • setup of System;
  • setup of all other elements in index order.

This means that if you initialize a variable where it would rely on a variable that’s not initialized yet, that could cause errors like that. But otherwise, I would have to take a look at your code again to really see what went wrong.

Update!

I checked your code and I’m pretty sure that those out of memory errors are right! You are running out of config memory, this is why the module behaves weirdly and refuses to accept the whole config.

What you’ll have to do in this case is to streamline your code. I’ve came up with a couple of suggestions here: Unique Download Link | WeTransfer.

The above reduced your code by about 5kbytes, and it now has no trouble loading in full as far as I can tell.

1 Like

Whoa, I didn’t expect that just moving the function definition from each encoders into system element would decrease the size by about 3Kb! Thanks for the help and giving me a heads-up on where to go.

Now I can use the whole config without problems so I shared it on the Profile Cloud! :hugs: