400 character limit for action chains

Hi, I don’t know if I’m missing something but I’m finding this extremely limiting for what can be done.

Are there any tricks to getting around this limit?

Thx

Can you post an example of your code? I’ve run into issues before but found that declaring functions and tables on the System element a good way to free up space. I was doing this on each element before when it really wasn’t needed. Shortening up variable names, can help. I’ve been able to pack a lot of functionality into some pretty tight spaces.

Are you writing the LUA yourself or using the Action Blocks?

Hi. I’m writing the code myself.

I’m trying to write functions on the System element but am having trouble calling them - I keep getting error messages like: global ‘myfn’ is not callable (a nil value)

Any ideas?

I think the “more about variables” section that talks about functions could have some examples of how we can define our own global and self functions and how to call them as it’s not seeming intuitive to me.

Can you post an example of a function that you’re defining in the ‘System’ element? Post the code verbatim.

I’m just heading off to spin but I’ll be home in a couple of hours. I can share what I’ve learned about declarations and scope when I get home.

Quickly on variables:

Anything variables defined on the ‘System’ ‘init’ tab can be referenced globally:

ch = 15

You can reference that globally for say, the MIDI channel for an entire page.

Variables defined on an element section are local to that section

local ch = 15

This could be used to set the channel for a specific element: pot encoder etc.

Variables declared with ‘self’ can be referenced from any of the sections within a physical element. If you declare the following in the ‘init’ tab of a physical element, you can reference it on the button or encoder page.

self ch = 15

Referenced with self.cc

Typing in phone in car. Apologies for the ‘quick and dirty’ rundown.

1 Like

I started from scratch and got the global function working - I think there was an error I wasn’t spotting. thx

So then I tried putting a function on an encoder element:

function my_fn(val)
print(val)
end

and calling this from the global setup:
element[0]:my_fn( “hello” )

and get the “method my_fn is not callable” error

I am new user too and I was struggling with the same things, I had to figure out some stuff by myself, but now things makes sense to me.

to call a global function, you make this on System Setup, for example:

function normalize(x)
   return x / 127
end

then on your encoders or buttons, you call the function with a codeblock

value = normalize(self:potmeter_value())
print(value)

To make code sort sometimes if/else can be replaced by a kind of ternary operator, like:

mode = 65
mode = (mode > 64) and 1 or 0
print(mode)

Cheers!

2 Likes

element[0] isn’t needed. To call the function from anywhere on the active page:

my_fn("hello")

Obviously you need a event to trigger it so, on a button page, try:

if self:button_state >= 1 then
       my_fn("hello")
else
end
1 Like

But i’m trying to call a function on a specific encoder from the global system state. I don’t want to call a global function, I want to call in to a “self” function

e.g. we can call element:encoder_value() to get the encoder value from a specific encoder when we are in system - I want to add my own function to call in the same way.

element[0] doesn’t trigger events. It’s only for referencing elements that aren’t your ‘self’. You can, however, trigger an event. Using a button as an example, if you wanted to call your function, you can something like this:

-- On the 'Button' tab

if self:button_value(20) and self:button_state(127) then
     my_fn("hello")
else
end

-- Using 'Midi rx' on the 'System' element as an example receiving CC 34 on MIDI channel 1

if ch == 0 and param1 == 34 then
     element[0]:button_value(20)
     element[0]:button_state(127)
else
end

So, when you receive CC 34, with any value, set the button value on the desired element to ‘20’ then set the button state to 127 which would be pressed. That triggers your function on that element based on those conditions

One thing I did learn was that you don’t need (and can’t use because it won’t work) element[0] for using any of the LED functions. The reason being is that all of those functions have a parameter for the element already. I was stuck on it for a bit until I realized this.

1 Like