show/hide objects when a menu option is selected

Discuss Lemur and share techniques.
jlys
Newbie
Posts:16
Joined:09 Dec 2011 13:32
show/hide objects when a menu option is selected

Post by jlys » 16 Jan 2012 16:52

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!

st8_livecontrol
Regular
Posts:83
Joined:04 Oct 2010 12:26

Re: show/hide objects when a menu option is selected

Post by st8_livecontrol » 16 Jan 2012 17:27

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);
}

jlys
Newbie
Posts:16
Joined:09 Dec 2011 13:32

Re: show/hide objects when a menu option is selected

Post by jlys » 16 Jan 2012 17:58

great! it works and opens lot of possibilities.. thank you big time for the quickness

moon matrix 0
Newbie
Posts:12
Joined:18 Nov 2014 13:55

Re: show/hide objects when a menu option is selected

Post by moon matrix 0 » 21 Nov 2014 14:56

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);
}

???

moon matrix 0
Newbie
Posts:12
Joined:18 Nov 2014 13:55

Re: show/hide objects when a menu option is selected

Post by moon matrix 0 » 21 Nov 2014 15:56

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);
}

ndivuyo
Regular
Posts:279
Joined:23 May 2014 00:24

Re: show/hide objects when a menu option is selected

Post by ndivuyo » 21 Nov 2014 18:38

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.

moon matrix 0
Newbie
Posts:12
Joined:18 Nov 2014 13:55

Re: show/hide objects when a menu option is selected

Post by moon matrix 0 » 21 Nov 2014 19:20

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 :(

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: show/hide objects when a menu option is selected

Post by Macciza » 22 Nov 2014 00:02

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.
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

ndivuyo
Regular
Posts:279
Joined:23 May 2014 00:24

Re: show/hide objects when a menu option is selected

Post by ndivuyo » 22 Nov 2014 01:30

Ah I see, I never used the 1,0 method, good to know for the future just in case. I'm a noob too ;)

moon matrix 0
Newbie
Posts:12
Joined:18 Nov 2014 13:55

Re: show/hide objects when a menu option is selected

Post by moon matrix 0 » 22 Nov 2014 02:03

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.

Post Reply