string scripting question
string scripting question
say i have a 16 step sequencer, built out of switches named Sequence_1, Sequence_2....-> Sequence_16
Is there some way, programatically, that I can access those object extension numbers?
for example, i have this simple conditional, to send a light value to Sequence_4:
//
if(integer_value >= 4)
Sequence_4.light_value=-0.3;
else
Sequence_4.light_value=-1;
Is there some way i can programatically script this so that i don't have to just repeat that same conditional 16 times for all my switches? Can i join a string "Sequence_" and then a float to make that message?
Is there some way, programatically, that I can access those object extension numbers?
for example, i have this simple conditional, to send a light value to Sequence_4:
//
if(integer_value >= 4)
Sequence_4.light_value=-0.3;
else
Sequence_4.light_value=-1;
Is there some way i can programatically script this so that i don't have to just repeat that same conditional 16 times for all my switches? Can i join a string "Sequence_" and then a float to make that message?
Re: string scripting question
Hi! Yes there is a way to do this.. you can access the contents of just about any object using a reference. I just began to use a method last month and rewriting older templates (tearing out a bunch of code as Joe puts it!).
SO what you can do is first create an array containing each 'Sequence_" object:
(make this run as an onload script in global with mySeq declared as a top-level variable so it is always ready for your scripting without the need to waste CPU on redeclaration):
mySeq={Sequence_1,Sequence_2,Sequence_3,Sequence_4,Sequence_5,Sequence_6..and so on};
Then in any script given that integer_value is 0 to sizeof mySeq-1 :
setexpression(mySeq[integer_value],'light_value',-1);
you can also have an array with light values for each sequence and apply that:
decl myLights={-0.1,-0.2,-0.3... and so on};//or set this in the object scope or as a global
setexpression(mySeq[integer_value],'light_value',myLights[integer_value]);
And that's it really.. if you want to update all 'Sequence_' lights or other values for a refresh, set to zero and so on just have a function with a for loop like so:
//dim led's
decl x;
for(x=0;x<sizeof(mySeq);x++) setexpression(mySeq[x],'light_value',-.1);
Hope this helps !
-Jay
SO what you can do is first create an array containing each 'Sequence_" object:
(make this run as an onload script in global with mySeq declared as a top-level variable so it is always ready for your scripting without the need to waste CPU on redeclaration):
mySeq={Sequence_1,Sequence_2,Sequence_3,Sequence_4,Sequence_5,Sequence_6..and so on};
Then in any script given that integer_value is 0 to sizeof mySeq-1 :
setexpression(mySeq[integer_value],'light_value',-1);
you can also have an array with light values for each sequence and apply that:
decl myLights={-0.1,-0.2,-0.3... and so on};//or set this in the object scope or as a global
setexpression(mySeq[integer_value],'light_value',myLights[integer_value]);
And that's it really.. if you want to update all 'Sequence_' lights or other values for a refresh, set to zero and so on just have a function with a for loop like so:
//dim led's
decl x;
for(x=0;x<sizeof(mySeq);x++) setexpression(mySeq[x],'light_value',-.1);
Hope this helps !
-Jay
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
Re: string scripting question
ok...i can NEARLY get my head around that.
BUT,
where do i put the Sequence_ object???
BUT,
where do i put the Sequence_ object???
Re: string scripting question
The Sequence_ object can go anywhere, but when you define the indirect object reference ("mySeq" vector) and it is outside the object scope then be sure to define the full object hierarchy to it..
so if your Sequence_ s are defined within two levels of three different containers/objects:
Container1.subContainer1.Sequence_1
Container2.subContainer1.Sequence_2
Container3.subContainer1.Sequence_3
You could make a initialize a global variable and set it:
mySeq{Container1.subContainer1.Sequence_1,Container2.subContainer1.Sequence_2,Container3.subContainer1.Sequence_3};
Then you can use mySeq[INDEX] ref's from a script located anywhere within the template.
code: setexpression(mySeq[integer_value],'light_value',myLights[integer_value]);
Another example, the sequences are all contained within the same "Container1.sequenceTop"
Container1.sequenceTop.Sequence_1
Container1.sequenceTop.Sequence_2
Container1.sequenceTop.Sequence_2
and your mySeq onload/init script is in " Container1.sequenceTop.initSeq()" but again with mySeq having beendefined as a global variable:
Then a script called "Container1.sequenceTop.initSeq" set to execute onLoad would be:
mySeq={Sequence_1,Sequence_2,subContainer1.Sequence_3};
I'd go with the second method simply to keep things tidy in a large project (and it's less coding!)..
If you variable scope is incorrect then the script editor or template editor will display the expression in red until you correct it.
Hope it helps!
-J
so if your Sequence_ s are defined within two levels of three different containers/objects:
Container1.subContainer1.Sequence_1
Container2.subContainer1.Sequence_2
Container3.subContainer1.Sequence_3
You could make a initialize a global variable and set it:
mySeq{Container1.subContainer1.Sequence_1,Container2.subContainer1.Sequence_2,Container3.subContainer1.Sequence_3};
Then you can use mySeq[INDEX] ref's from a script located anywhere within the template.
code: setexpression(mySeq[integer_value],'light_value',myLights[integer_value]);
Another example, the sequences are all contained within the same "Container1.sequenceTop"
Container1.sequenceTop.Sequence_1
Container1.sequenceTop.Sequence_2
Container1.sequenceTop.Sequence_2
and your mySeq onload/init script is in " Container1.sequenceTop.initSeq()" but again with mySeq having beendefined as a global variable:
Then a script called "Container1.sequenceTop.initSeq" set to execute onLoad would be:
mySeq={Sequence_1,Sequence_2,subContainer1.Sequence_3};
I'd go with the second method simply to keep things tidy in a large project (and it's less coding!)..
If you variable scope is incorrect then the script editor or template editor will display the expression in red until you correct it.
Hope it helps!
-J
bananas wrote:ok...i can NEARLY get my head around that.
BUT,
where do i put the Sequence_ object???
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
Re: string scripting question
oh man, you really are awesome!
i'll get into this again tomorrow and see how i go. But i can see how it works now. Cheers
i'll get into this again tomorrow and see how i go. But i can see how it works now. Cheers
Re: string scripting question
if only I had known this object reference stuff 10 months ago!! it would have been a time saver.
cheers !
cheers !
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
Re: string scripting question
ok... i have redone what i wanted to do.. and i hoped that this would work. but no luck.
i have 16 rows of switches, and i have globally defined an array full of references to all those switches:
all_switches={'Switches_1', 'Switches_2',....'Switches_16'}
each switch has a variable 'brightness', which sets the light value
finally, there is a fader along the bottom of the switches, which i want to use to set the 'last step'. So, i want that fader to dim the lights of all switches to its right.
the fader x value is scaled to 0-15 by: fader_pos = floor(x*15.999)
and then finally, the bit that i'm having trouble with - i made a script in the Fader object called 'light_switches()', which looks like this:
decl n;
decl bright_value;
for(n=0;n<=15;n++)
{
if (n <= fader_pos)
bright_value = -0.3 ;
else
bright_value = -1 ;
setexpression(all_switches[n], 'brightness', bright_value);
}
but it ain't working
any ideas?
i have 16 rows of switches, and i have globally defined an array full of references to all those switches:
all_switches={'Switches_1', 'Switches_2',....'Switches_16'}
each switch has a variable 'brightness', which sets the light value
finally, there is a fader along the bottom of the switches, which i want to use to set the 'last step'. So, i want that fader to dim the lights of all switches to its right.
the fader x value is scaled to 0-15 by: fader_pos = floor(x*15.999)
and then finally, the bit that i'm having trouble with - i made a script in the Fader object called 'light_switches()', which looks like this:
decl n;
decl bright_value;
for(n=0;n<=15;n++)
{
if (n <= fader_pos)
bright_value = -0.3 ;
else
bright_value = -1 ;
setexpression(all_switches[n], 'brightness', bright_value);
}
but it ain't working
any ideas?
- Attachments
-
- global_brightness.jzml
- (8.58 KiB) Downloaded 136 times
Re: string scripting question
nice layout!
the problem is that your global needs to refer to objects not strings.. so just remove the single quotes from each switch name and.. should work!
the problem is that your global needs to refer to objects not strings.. so just remove the single quotes from each switch name and.. should work!
Dashboard gear control templates: User 112 Idx :: LModIt Lite :: SVG image converter for Lemur Canvas
Re: string scripting question
arghh! right.
i had done that before, but before i'd made all the switch objects, so it was giving me errors.
let's see how it goes now
i had done that before, but before i'd made all the switch objects, so it was giving me errors.
let's see how it goes now
Re: string scripting question
Thank you so much Jay, you're a blumin' legend!
so stoked!
so stoked!
- Attachments
-
- global_brightness.jzml
- (24.22 KiB) Downloaded 133 times