if then. please help

Discuss Lemur and share techniques.
Smurphd
Newbie
Posts: 8
Joined: 19 Mar 2015 08:41

if then. please help

Post by Smurphd »

hi.
i got lemur a week ago or so and and everything is good until i need scripting.
im trying to control rows and columns of a switch object with another switch.
i can make it work with a firstof(x) but i need to stuff in a if then but i just cant get it right.
hope you understand what im trying to do from looking at the flawed code ive put here.
ive been stuck on this for days.

Code: Select all

decl val;
val=firstof(x);
if (val==0) val = '1';   
if (val==1) val = '4'; 
setattribute (Pads1, 'column', val);
frank
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: if then. please help

Post by oldgearguy »

Frank, Can you explain in words what you are trying to accomplish?

The code fragment is not clear enough in that the setattribute() call seems to be setting the number of columns in your pad array, which may or may not be what you're after. the val value does not have to be quoted (i.e. - if (val == 1) val = 4;) and there's other oddities, so a description would be worthwhile.
Smurphd
Newbie
Posts: 8
Joined: 19 Mar 2015 08:41

Re: if then. please help

Post by Smurphd »

I have One switch object with multiple rows and columns that I want to use to set the rows and columns on another switch object.
I'll call the first one banks and the second presets
I'm gonna use it for changing banks and presets on a fx machine with a lot of banks and presets.
So that if I choose bank1 in the first switch object it will set the size by rows and columns on the second one and so on. I also want to set the names for the preset the same way but I think if I figure out how to set the sizes I'll also be able to figure out how to change names. Hope that's clear enough to make sense of. I'm not home right now so I can't upload my sketch.
I really appreciate you taking time to have a look at this.
ndivuyo
Regular
Posts: 278
Joined: 23 May 2014 00:24

Re: if then. please help

Post by ndivuyo »

hey there. If you post it we could help even better. (attach it)
just like oldergearguy said It seems like your problem is using the ''
don't use '' when stating a number, that is for symbols. so instead:

decl val;
val=firstof(x);
if (val==0) val = 1;
if (val==1) val = 4;
setattribute (Pads1, 'column', val);

should work. As for labeling, you will use the '' cause they are symbols. Depending on how many names you are using and all, you may setup changing the names differently. I would create an array with the name options and use a for loop to pick and choose them into a blank array and then use that array for the label attribute. so...

decl blank,names = {'n1','n2','n3','n4'};
decl size = sizeof(Pads1.x);
for(i=0;i<size;i++){
if(some kind of condition that's relevent) blank=size;
else blank=blank; I don't know this could change depending on your goals
}
setattribute (Pads1, 'labels', blank);

make sure multilabel is checked for the object
Something like that, it depends on exactly what you are doing, post or comment if you have further questions/confusion!
Last edited by ndivuyo on 24 Mar 2015 17:11, edited 1 time in total.
Smurphd
Newbie
Posts: 8
Joined: 19 Mar 2015 08:41

Re: if then. please help

Post by Smurphd »

Thanks a lot, can't wait till I get home so I can try some things out.ill also upload the sketch to make things more clear.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: if then. please help

Post by oldgearguy »

although, having

if (val == 0) val = 1;
if (val == 1) val = 4;

in a row like that won't do what you think it will do.

if it's 0, set it to 1. Next, check if it is 1, if so, set it to 4.

That's why we ask for words - maybe you wanted

if (val ==0)
val = 1;
else if (val == 1)
val = 4;

??
ndivuyo
Regular
Posts: 278
Joined: 23 May 2014 00:24

Re: if then. please help

Post by ndivuyo »

yea good point, I was testing it with a second variable, that's why it worked for me. woops!
Smurphd
Newbie
Posts: 8
Joined: 19 Mar 2015 08:41

Re: if then. please help

Post by Smurphd »

ill spend the evening thinking about what you wrote and see if i can figure it out. ive attached the sketch for the thing im working on though im experimenting with two switch objects with only two switches not to get too confused.
Attachments
preset selector.jzml
(6.45 KiB) Downloaded 34 times
ndivuyo
Regular
Posts: 278
Joined: 23 May 2014 00:24

Re: if then. please help

Post by ndivuyo »

So I'm a little confused, you want the preset switch on the right to determine the number of rows and columns on the switch on the left? So if it's on number 4 there will be 4 rows and 4 columns? I assume that's not what you're thinking, especially because you can only go to 16x16. Or is the number more complex? In which case you could make an array with the different number of rows and columns.

If that is what you are thinking though, then you can just set the attribute size directly the the index (val in your example). but you can only go up to 16x16

The labelling script shouldn't be executed 'on frame'. It should be 'on load' or if you change it around, make it 'Manual'. Then when you execute another script on 'x' or whatever, call the labelling script by typing it's name: bankNames();

anyway just need a few more details about what changes the size and how the labelling will be changed
Smurphd
Newbie
Posts: 8
Joined: 19 Mar 2015 08:41

Re: if then. please help

Post by Smurphd »

sorry im really bad at explaining things like this, which is also why i tried with the code example.
but ive figured it out, i think. the lack of ``around numbers and the else if sorted me out.Thanks alot. so so far so good. next up is the naming.
you can see the example ive attached to clear the confusion a bit. i wanted the bank switch on the left to determine the rows and colums on the preset switch to the right.the banks contain everything between 6-80 or so algorithms. if theres a way smarter way to do it with array´s id like to know though im not sure i would understand it. i really suck at programming. but i like to know if im doing things in a smart way or a really clumsy way anyway.
Attachments
set rows n`columns.jzml
(4.43 KiB) Downloaded 33 times
Post Reply