Help with Broadcaster to make componets visible and enabled
-
I have 2 arrays one with btns and another one with knobs
Btns = [btn1, btn2, btn3]
Knbs = [knb1, knb2, knb3]I want to hide the knb according to the btn's value, If btn1 is on or has a. value of 1 then the knb1 should be visible and enabled. I tried this without using a broadcaster but with a callback function using the knb.set("visible", true); But the thing with this is that when I switch the preset it hides the knb even when the button is active. I think using a broadcaster can fix it as by switching presets it will update those knbs and btns in the backend.
I would really appreciate if someone can help me with this
-
@Onik-Sisodiya so this will not work when switching presets?
inline function onBtnsControl(component, value) { local idx = Btns.indexOf(component); Knbs[idx].showControl(value); Knbs[idx].set("enabled", value); } for (b in Btns) b.setControlCallback(onBtnsControl);
-
@Onik-Sisodiya Thanks @ulrik for the snippet. I have the similar callback for the functionality but however when switching the preset it hides the knb even when the button is active. But I gave a try with a broadcaster and attached a knob and a button and it looks like it works perfectly. I'm afraid I don't have to use a seperate broadcaster for pair of button annd a knob.
// Broadcaster definition
const var btnknb = Engine.createBroadcaster({
"id": "btnknb",
"args": ["component", "value"],
"tags": []
});// attach to event Type
btnknb.attachToComponentValue(["SendAmountOnOff3"], "");// attach first listener
btnknb.addComponentPropertyListener(["AmountWheel3"], ["visible", "enabled"], "dsas", function(index, component, value){
return value;
});Like this, If there's anyway to make it maintainable and with less code would be really helpful.
-
@Onik-Sisodiya Just got it figured out!! Thanks again