scripting strings

Discuss problems and solutions.
Identity-Problem
Newbie
Posts: 5
Joined: 20 Jun 2014 09:07
Location: poland

scripting strings

Post 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
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

;)
Attachments
Pad-battery-display.jzml
(2.66 KiB) Downloaded 65 times
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post 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.
Identity-Problem
Newbie
Posts: 5
Joined: 20 Jun 2014 09:07
Location: poland

Re: scripting strings

Post 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
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post 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.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post 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
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: scripting strings

Post 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 . . .
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]
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post 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!
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post 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.
Post Reply