Make a Panel Visible in oninit
-
I have the following code.
No matter what order I place the buttons and panels, panel 4 is always visible and the rest are invisible.
The buttons work just fine manually. But they don't initialize properly.
I want panel 1 to be visible and the rest to not be when the program loads... not after a button is pressed.
How can this be done?
const var Rhythm_Button4 = Content.getComponent("Rhythm_Button4"); const var Rhythm_Button3 = Content.getComponent("Rhythm_Button3"); const var Rhythm_Button2 = Content.getComponent("Rhythm_Button2"); const var Rhythm_Button1 = Content.getComponent("Rhythm_Button1"); const var StylesPanel4 = Content.getComponent("StylesPanel4"); const var StylesPanel3 = Content.getComponent("StylesPanel3"); const var StylesPanel2 = Content.getComponent("StylesPanel2"); const var StylesPanel1 = Content.getComponent("StylesPanel1"); const var RhythmDisplayNumber = Content.getComponent("RhythmDisplayNumber"); function getActiveRadioButton() { if (Rhythm_Button4.getValue()) { return "4"; } else if (Rhythm_Button3.getValue()) { return "3"; } else if (Rhythm_Button2.getValue()) { return "2"; } else if (Rhythm_Button1.getValue()) { return "1"; } else { return "1"; } } inline function onRhythm_Button4Control(component, value) { RhythmDisplayNumber.set("text", getActiveRadioButton()); StylesPanel1.set("visible", 0); StylesPanel2.set("visible", 0); StylesPanel3.set("visible", 0); StylesPanel4.set("visible", 1); }; Content.getComponent("Rhythm_Button4").setControlCallback(onRhythm_Button4Control); inline function onRhythm_Button3Control(component, value) { RhythmDisplayNumber.set("text", getActiveRadioButton()); StylesPanel1.set("visible", 0); StylesPanel2.set("visible", 0); StylesPanel3.set("visible", 1); StylesPanel4.set("visible", 0); }; Content.getComponent("Rhythm_Button3").setControlCallback(onRhythm_Button3Control); inline function onRhythm_Button2Control(component, value) { RhythmDisplayNumber.set("text", getActiveRadioButton()); StylesPanel1.set("visible", 0); StylesPanel2.set("visible", 1); StylesPanel3.set("visible", 0); StylesPanel4.set("visible", 0); }; Content.getComponent("Rhythm_Button2").setControlCallback(onRhythm_Button2Control); inline function onRhythm_Button1Control(component, value) { RhythmDisplayNumber.set("text", getActiveRadioButton()); StylesPanel1.set("visible", 1); StylesPanel2.set("visible", 0); StylesPanel3.set("visible", 0); StylesPanel4.set("visible", 0); }; Content.getComponent("Rhythm_Button1").setControlCallback(onRhythm_Button1Control);
-
It's probably to do with your saveInPreset settings for the controls. Save in preset overrides anything you set in on init.
That
getActiveRadioButton
function could be improved. -
I'm all ears...
Please share how the getActiveRadioButton could be improved. I'm interested.
I'll check the save in preset settings.
I do want the buttons saved in preset, but I need to be able to set the button's states during init.
[edit]
Just tried toggling save in preset - makes no difference
-
@larryseyer said in Make a Panel Visible in oninit:
Please share how the getActiveRadioButton could be improved. I'm interested.
Get the buttons into an array like this
const Rhythm_Buttons = Content.getAllComponents("Rhythm_Button\\d");
Then in your function (inline function) you can just grab the index of the active one.
inline function getActiveButtonIndex() { for (x in Rhythm_Buttons) { if (x.getValue() return Rhythm_Buttons.indexOf(x); } }
-
@larryseyer said in Make a Panel Visible in oninit:
I do want the buttons saved in preset, but I need to be able to set the button's states during init.
In that case you'll need to disable the built in radio groups and script your own system instead. It's very easy to do if your buttons are in an array. First turn off all the buttons and turn on the one that was clicked.
-
Code Looks better but I get errors:
Interface:! AssignRhythmButtonsToPanels.js (10): Found 'return' when expecting ')' {SW50ZXJmYWNlfEFzc2lnblJoeXRobUJ1dHRvbnNUb1BhbmVscy5qc3wxODZ8MTB8MTM=} Interface:! AssignRhythmButtonsToPanels.js (10): Found 'return' when expecting ')' {SW50ZXJmYWNlfEFzc2lnblJoeXRobUJ1dHRvbnNUb1BhbmVscy5qc3wxODZ8MTB8MTM=}
-
Not sure I understand exactly what you mean.
Let me repeat it back to you and see if this is correct...
Set all panels off except for 1st one (the one I want to be active)
Put buttons into an array (not quite sure how to do this yet)
Set all buttons 'off' initially, but when a button is pressed, it is set to 'on' in the array.Is that right?
-
@larryseyer said in Make a Panel Visible in oninit:
Code Looks better but I get errors:
Oh yeah, looks like there's a typo. It's an easy fix, see if you can find it. The error message tells you exactly what's wrong and on which line.
@larryseyer said in Make a Panel Visible in oninit:
Not sure I understand exactly what you mean.
I have a video showing how to do this - https://youtu.be/_s7LTRz8pEc?si=UnFcPPN26jyWEUZo
-
Found the typo... fixed it...
Thanks for the video.
I've been watching your videos ever since I first found out about HISE (which was only a couple of weeks ago)
Funny thing is, looks like I've already watched that particular video.
I'll watch it more closely this time.
Thanks for all your help and rapid response.
BTW, also I really appreciate the work you've done with the instructional videos...
Great job!
All the very best to you!
L