Button.setValue(1) oninit not reflected in UI
-
Hi,
I'm encountering an issue where using setValue(1) on a button component does not visually update the button state, even though getValue() correctly returns 1. Here's a minimal example to replicate the problem:
const var button = Content.getComponent("Button1"); button.setValue(1); Console.print(button.getValue()); // Prints 1
While the console confirms that the button's value has been set to 1, the button does not visually reflect the change. Is there an additional step required to trigger the visual update for button components?
-
@CyberGen you need to set button.changed() as well, however the .changed() will not work during the onInit callback.
Where do you set the value change?
-
@ulrik I'm currently setting the value in oninit. I'd like the button to start in the on position. I had tried the .changed() as well as setting the default value property to 1, but neither of those did the trick.
-
@CyberGen does it have "saveInPreset" enabled?
In that case it will remember the value you set when you save the project -
@CyberGen What about calling the change after a delay?
Content.callAfterDelay(500, function(){ Knob1.setValue(1); Knob1.changed(); }, this);
-
@Dan-Korneff & @ulrik So, enabling "Save in Preset" works, but I didn’t want to rely on that for this, primarily because patches can be edited and that could mess with the initial setup that I'm looking for.
I wasn’t aware of the callAfterDelay() function. That did the trick—thank you for the tip!
I have to say, though, it’s still a convoluted way to achieve this, especially considering how many buttons I’d need to set it up for. I’m still wondering why simply setting the default value doesn’t work with script buttons. It seems to work fine with other components.
-
@ulrik So I just realized, what you are saying here is that I should turn off the save in preset mode. That makes the setValue work. But not the default value.
-
@CyberGen The default value of buttons seems to not be useful. If a control is set to saveInPreset then anything you set in on init will be overwritten immediately after by the stored value.
-
@d-healey I can confirm that the default value for buttons is not working here either.
-
@VirtualVirgin said in Button.setValue(1) oninit not reflected in UI:
is not working
What do you expect it to do?
-
@d-healey If I set the default value to "1" and recompile I would expect the button to be on.
Is that not what it is meant to do? -
@VirtualVirgin said in Button.setValue(1) oninit not reflected in UI:
Is that not what it is meant to do?
It doesn't do that for any other control. With slider the default value is the value it will reset to when you double click it.
-
@d-healey Right, I see. What is it meant for then?
-
@d-healey said in Button.setValue(1) oninit not reflected in UI:
The default value of buttons seems to not be useful.