Page 1 of 2
scripting strings
Posted: 21 Jun 2014 08:00
by Identity-Problem
hi there,
lets say i want to display a battery percentage as Pad's label so that it will show
for example :"Battery : 55 %"
My problem is that i don't know how to script a string so that only one object will be needed to do so ( in this case :Pads object)
I'm new to this and as far as i understand it the script should be something like:
set attribute(Pads, 'labels',{ 'Battery :' , floor(battery*100) , '%'});
but i'm obviously doing smith wrong. any help appreciated
Re: scripting strings
Posted: 21 Jun 2014 10:50
by Softcore
Re: scripting strings
Posted: 21 Jun 2014 11:57
by Identity-Problem
thx ALOT!
Re: scripting strings
Posted: 21 Jun 2014 13:06
by oldgearguy
Also note that unless floor(battery*100) is doing something different than I think, I only see updates every 5% (i.e. - 100, 95, 90, 85, etc). I have never seen 92 or 78 or 63. So if you don't see it constantly updating, that probably working as expected.
Re: scripting strings
Posted: 21 Jun 2014 16:18
by Identity-Problem
i noticed. i haven't seen 73 or 58 as well, but that's fine(don't need so much precision with battery display). anyway thanks!
....
another problem is that i want to see CPU percentage from Reaktor on OSC expression. i can get it right on Monitor because it has 'precision' chechbox, but on pads it displays the whole OSC message like 1,2346456 or so . i only want first three digit to be displayed on second pad and a BPM value o third Pad.
set attribute (Pads, 'labels', {battery, CPU, BPM};
still didn't figure out how to do this
cheers
Re: scripting strings
Posted: 22 Jun 2014 01:52
by oldgearguy
Identity-Problem wrote:i noticed. i haven't seen 73 or 58 as well, but that's fine(don't need so much precision with battery display). anyway thanks!
....
another problem is that i want to see CPU percentage from Reaktor on OSC expression. i can get it right on Monitor because it has 'precision' chechbox, but on pads it displays the whole OSC message like 1,2346456 or so . i only want first three digit to be displayed on second pad and a BPM value o third Pad.
set attribute (Pads, 'labels', {battery, CPU, BPM};
still didn't figure out how to do this
cheers
Can't do it. Even displaying the Monitor.value in another with shows the entire fraction.
The quick, big hammer, not elegant answer is to create Monitors on top of the pads and display to the Monitors instead of the pad labels.
Re: scripting strings
Posted: 22 Jun 2014 13:09
by Softcore
In monitor objects you can set the precision option go get as many digits as you desire....using pads labels though, thats not possible
Re: scripting strings
Posted: 23 Jun 2014 01:44
by Macciza
Hi
Should be able to just do a little maths to get what you want
Multiply and truncate to get the number of digits need and divide back again
ie floor(1.2346456*1000)/1000 = 1.234
Cheers
PS I guess you could also use round to be a bit more accurate . . .
Re: scripting strings
Posted: 23 Jun 2014 11:02
by Softcore
That was my initial reply macciza but I edited because I believe you will still get
1.23400000 at the label
haven't checked though, so Im not sure!
Re: scripting strings
Posted: 23 Jun 2014 12:24
by oldgearguy
Softcore wrote:That was my initial reply macciza but I edited because I believe you will still get
1.23400000 at the label
haven't checked though, so Im not sure!
I thought so too. I have a couple alternate methods (to contradict my original post - sometimes I just need more time to mull it over)
NOTE, CAVEAT, WARNING, DISCLAIMER - I don't have a Lemur environment to test this - I keyed it in believing it will work, but you should test it in isolation before sending out production code with it embedded....
Assuming you want to just display the info and not do further math on it, you can try this:
create a manual script --
convert(n, p)
{
decl multiplier, num, frac, answer;
multiplier = pow(10, p);
num = floor (n);
frac = floor((n - num) * multiplier);
answer = num+'.'+frac;
return(answer);
}
then in your code you can do something like: setattribute(myPad, 'label', convert(num, 3));
If you always want to just show 3 positions, you can dispense with the second parameter and hardcode 1000 in the script, but I thought I might as well make it generic.