Page 1 of 2
show/hide objects when a menu option is selected
Posted: 16 Jan 2012 16:52
by jlys
Hi again!
As the title says, I would like to show/hide objects depending on which option is selected in a LemurMenu.
how do i do that?
the script i would like to use is:
-when Option 1 is selected:
show(ContainerA,1);
show(ContainerB,0);
-when Option 2 is selected:
show(ContainerA,0);
show(ContainerB,1);
etc..
Thanks by advance!
Re: show/hide objects when a menu option is selected
Posted: 16 Jan 2012 17:27
by st8_livecontrol
add a multiline script to your menu, with execution on expression = selection
if(selection == 0) {
show(ContainerA,1);
show(ContainerB,0);
} else if (selection == 1) {
show(ContainerA,0);
show(ContainerB,1);
}
Re: show/hide objects when a menu option is selected
Posted: 16 Jan 2012 17:58
by jlys
great! it works and opens lot of possibilities.. thank you big time for the quickness
Re: show/hide objects when a menu option is selected
Posted: 21 Nov 2014 14:56
by moon matrix 0
Quick question...
I see guys using the switch instead of menu. Any advantage/disadvantage or purely cosmetic?
Also, how would I write the code in order to have more than 2?
Like this?
if(selection == 0) {
show(ContainerA,1);
show(ContainerB,0);
} else if (selection == 2) {
show(ContainerC,0);
show(ContainerD,1);
} else if (selection == 3) {
show(ContainerC,0);
show(ContainerD,1);
}
???
Re: show/hide objects when a menu option is selected
Posted: 21 Nov 2014 15:56
by moon matrix 0
or maybe...
if(selection == 0) {
show(ContainerA,1);
show(ContainerB,0);
show(ContainerC,0);
Show(ContainerD,0);
Show(ContainerE,0);
} else if (selection == 1) {
show(ContainerA,0);
show(ContainerB,1);
show(ContainerC,0);
show(ContainerD,0);
show(ContainerE,0);
} else if (selection == 2) {
show(ContainerA,0);
show(ContainerB,0);
show(ContainerC,1);
show(ContainerD,0);
show(ContainerE,0);
} else if (selection == 3) {
show(ContainerA,0);
show(ContainerB,0);
show(ContainerC,0);
show(ContainerD,1);
show(ContainerE,0);
} else if (selection == 4) {
show(ContainerA,0);
show(ContainerB,0);
show(ContainerC,0);
show(ContainerD,0);
show(ContainerE,1);
}
Re: show/hide objects when a menu option is selected
Posted: 21 Nov 2014 18:38
by ndivuyo
I can't tell what would work, because I don't know your project.
But usually I can get away with using logical and/or statements inside the show() itself making it pretty clean and simple.
What is the 1 and 0 in this instance?? That would help a lot to know
For example:
show(ContainerA, selection==0);
show(ContainerB, selection==1);
show(ContainerC, selection==2);
show(ContainerD, selection==3);
show(ContainerE, selection==4);
Like I said, I don't know what the 1 and 0 are, but if you had additional circumstances, you can use || or && in there
show(ContainerA, selection==0 && x==1);
something like that. You shouldn't need all those if statements in there (again I don't know the context though). Those containers will automatically hide themselves if the condition isn't met, no need to spell it out for them.
Re: show/hide objects when a menu option is selected
Posted: 21 Nov 2014 19:20
by moon matrix 0
Doesn't 1 and 0 decide if it's showing or not? I was using 0 for "hide" and 1 for "show". Remember I'm a noob so I might be completely wrong
Re: show/hide objects when a menu option is selected
Posted: 22 Nov 2014 00:02
by Macciza
Yep the 1 or 0 in the show function are for hide and show, not sure exactly what he was asking though . .
Those 0 or 1s can come from anywhere ie show(container, switch.x) shows when switch is pressed ..
You're taking the long way around, remember that selection==n parts yields a 0 or 1 as well so you may as well use that
A common coding rule is to not repeat yourself - DRY = Don't Repeat Yourself WET = We Enjoy Typing . Keep it dry!
Also expressed as a rule of three - if you are repeating something more then twice then don't!
So look at the code he has offered and work out what it does for different input values
If the selection is 1 then selection==1 returns 1 and all the rest return 0 and so on . . .
See how this plugs the right values in all the right places and achieves the same thing as the other code just more directly.
Re: show/hide objects when a menu option is selected
Posted: 22 Nov 2014 01:30
by ndivuyo
Ah I see, I never used the 1,0 method, good to know for the future just in case. I'm a noob too
Re: show/hide objects when a menu option is selected
Posted: 22 Nov 2014 02:03
by moon matrix 0
if(selection == 0) {
show(Container0, selection==0);
show(Container1, selection==1);
show(Container2, selection==2);
show(Container3, selection==3);
show(Container4, selection==4);
show(Container5, selection==5);
show(Container6, selection==6);
show(Container7, selection==7); }
It doesn't work
My selections are other containers. I'm basically creating one interface that contains several.