Troubleshooting
scripting strings
Started by Identity-Problem on .
Sign in or create an account to join the conversation.
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
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
thx ALOT!
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.
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
....
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
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.
In monitor objects you can set the precision option go get as many digits as you desire....using pads labels though, thats not possible
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 . . .
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 . . .
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!
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)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!
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.
I had a second method, but I really need to key it into the editor and see if it runs.
The basic idea is to turn a number into a string, then subarray it:
strNum = ''+num; // concatenating a null string to a number turns it into a string
answer = subarray(strNum, 0, sizeof(strNum) - 3);
Given that subarray() and sizeof() work on arrays and not strings, this idea might need tweaking...
The basic idea is to turn a number into a string, then subarray it:
strNum = ''+num; // concatenating a null string to a number turns it into a string
answer = subarray(strNum, 0, sizeof(strNum) - 3);
Given that subarray() and sizeof() work on arrays and not strings, this idea might need tweaking...
Just checked this last one because if it worked it would be a great revelation.......
But it didnt lol! Obviously subarray doesnt work on strings
But it didnt lol! Obviously subarray doesnt work on strings
There are of course a lot of ways to create a script but it all depends on what exactly is the expected range of our value....that 1.38974934 got me wondering (seeing > 1)
I think my script will handle any possible numeric value. That's why I treated the whole number part and fractional part separately and then glued them back together around the decimal point at the end.Softcore wrote:There are of course a lot of ways to create a script but it all depends on what exactly is the expected range of our value....that 1.38974934 got me wondering (seeing > 1)
Oh yes, your first one, most definitely - I was thinking something along your second approach......
I'll check it out in a Lemur template and report back!
I'll check it out in a Lemur template and report back!
OK, I can confirm the first solution of Oldgearguy works with a slight change in the manual script....
See....this one is NOT converted into a string:
And here is an example
oldgear-fraction.jzml
See....this one is NOT converted into a string:
answer = num+'.'+frac;
THIS ONE though is:answer =''+ num+'.'+frac;
(for some reason, Lemur string concatenation assumes a summed variable to be a string, only when the first element of the concatenation is a string)And here is an example
oldgear-fraction.jzml
Thanks for checking and correcting. Funny -- I had written it the first way initially then deleted it thinking I had done string cats before without the first part being a string.Softcore wrote:OK, I can confirm the first solution of Oldgearguy works with a slight change in the manual script....
See....this one is NOT converted into a string:
THIS ONE though is:answer = num+'.'+frac;
(for some reason, Lemur string concatenation assumes a summed variable to be a string, only when the first element of the concatenation is a string)answer =''+ num+'.'+frac;
And here is an example
I haven't been home much and can't install/run the Lemur editor at work, so I appreciate you taking the time to punch it in and fix it.
No worries!
On the (ironic) contrary, after some stupid false procedures of telecommunication companies, Im left with no internet connection at home, possibly for the next 10 - 15 days too. Thank God there's internet and a few spare moments at my workplace. Of course laptop at work also has Lemur editor installed
On the (ironic) contrary, after some stupid false procedures of telecommunication companies, Im left with no internet connection at home, possibly for the next 10 - 15 days too. Thank God there's internet and a few spare moments at my workplace. Of course laptop at work also has Lemur editor installed