Reuse script in multiple widget

I have a bunch of buttons inside a modal and I have another toggle widget in my project. I want depending on the value of that toggle to close the parent modal whenever I press a button inside it. I can easily do that with a script:

if(get("closemodal") === 1) {
set("parent", 0);
}

Is there any way to "inherit" a script so that I don't have to repeat it on every single child widget? Or is repeating it the only way possible?

Place a script widget in the modal with this script in onValue, set its linkId to
<< closeLink
and set all the other widgets' (that ought to close the modal when interacted with) linkId to
>> closeLink

1 Like