Skip to main content

Inter-Grid communication

Ever wanted to just press a button on one module that would change how another one behaves? Well, now you can.


The immediate_send() function

As of Grid Editor version 1.3, you'll be able to find a new function that's called:

immediate_send(target_relative_postion_x,target_relative_postion_y, 'lua code')
-- here 'lua code' can be anything that you would normally write in the code editor of Grid Editor
-- and the relative positions are the module you're trying to address, (0,0,'lua code') being itself, (nil,nil,'lua code') being all modules

This function executes lua_code on the module addressed by x and y. Use x = nil and y = nil to trigger on all modules.

What's this for?

This new function allows you to share data between modules in a way that wasn't really possible before.

Now, creating new functions that all modules understand equally, or setting variables that stay in sync no matter which module you change them on (as long as you keep telling the others it changed) should be a lot easier to implement, thanks to immediate_send().

How immediate_send() works

The function will send to specific or all modules a text string which they will immediately execute.

Try out the examples below in Grid Editor! That string will have to be a lua code snippet like so:

immediate_send(nil, nil, 'print("Hello world!")')
-- we should see 'Hello world!' appear in the debug monitor the same amount of times as we have modules connected
immediate_send(nil, nil, 'print(module_position_x())')
-- here we should see the position of our connected modules in the debug monitor on the x axis
immediate_send(nil, nil, 'print("I am the " .. module_position_x() .. ". module on the X axis.")')
-- and this one should combine the two functions above

We can and will have to use the .. concatenation operator where we want to string (heh) together multiple elements into a string which we send out in the end.

The modules on the receiving end, will interpret everything as ONE string. Meaning when wanting to use variables in arguments of functions you will have to use the .. operator AND add commas in between as well like this:

immediate_send(nil, nil, 'led_value(0,2' .. val .. ')')
-- this function controls the LED brightness on all connected modules, based on the state of the control element sending out the above function
immediate_send(1, 0, 'led_value(0,2' .. val .. ')')
-- this function controls the LED brightness on the module which position is x = 1, y = 0, relative to the module position where immediate_send() is called, combined with the state of the control element sending out the above function

Remember that the led_value(index, layer, value) function's second layer argument can have two values, 1 for button changes and 2 for fader, potentiometer or encoder rotation changes. While you test this out, make sure you address the correct layer.

tip

The immediate_send() function's first two arguments - x and y coordiantes - are relative to the module where the function is called. If you want to send a message to all modules, use nil for both x and y arguments.

Things to try

Try using the above function in a Code Block on a potentiometer and watch the first LED get brighter on each module in your setup! You can find it in Profile Cloud, it's called "Coloring with immediate send".

Setting LED colors on all connected Grid modules with just one fader!