Sysex text on button dynamic label

Hi!
In order to retrieve text from the DAW into OSC I used a few examples of the forum and have a script widget with the following onValue script

locals.text = locals.text || Array(112).fill(" "); // persistent variable to store full text

var nValue = Number("@{parent.variables.n}");  // Replace this with the actual way to get the value in your environment
var targetString = "f0 00 01 06 02 12 0" + String(nValue - 1) + " 01";

if (value.includes(targetString)) {
  
    var d = value.split(" ").slice(8).map(x => parseInt(x, 16)), // hex to int
        pos = d[0], // first byte -> position
        text = d.slice(1).map(x => String.fromCharCode(x)); // rest -> updated characters

    text.pop(); // drop sysex closing byte

    // update characters
    for (var i = 0; i < 30; i++) {
        locals.text[i + pos] = text[i]; // update 
    }

    // update text widget
    var currentText = locals.text.slice(0,56).join("") + "\n" + locals.text.slice(56).join("");
    var lcdName = "lcd_" + String(nValue) + "_2";
    set(lcdName, currentText);

}

updating a text widget (id:lcd_@{parent.variables.n}_2)

I was wondering if I can achieve the same purpose of displaying the daw text, but instead of updating a text widget, dynamically update the label of a button widget.

Thank you

First I strongly recommend you replace

Number("@{parent.variables.n}")

with

getProp('parent', 'variables').n

Then you could write VAR{mylabel} in the button's label property (creates a custom variable named mylabel scoped to that widget) and update it by calling

setVar('button_id', 'mylabel', currentText)

Thank you so much!
Not wanting to take more of your time than necessary, but as a learning opportunity what is the advantage of using getProp syntax?

Advanced syntaxes should be avoided in scripts (onXXX properties), here the @{} forces a reevaluation of the code (when parent.variables changes o-s-c must figure out what @{} means, produce the resulting js code and compile it before it can run) and is prone to error and workarounds (the use of Number() is one), whereas getProp() only fetches the desired property upon execution without affecting the property's lifecycle.

Thank you so much!
There are many ways to reach Rome, but indeed some are for sure less bumpy than others! :wink: