Displaying integers in a text object?

Discuss Lemur and share techniques.
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Displaying integers in a text object?

Post by GV1 »

How can I display an integer in a text object?

The following example doesn't work:

Code: Select all

decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', val);
But if I do the following it works fine:

Code: Select all

setattribute(OctaveLabel.octaveValue, 'content', '5');
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Displaying integers in a text object?

Post by oldgearguy »

try this:

Code: Select all

decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', ''+val);

:shock:

outside the box man, outside the box.
MrCorba
Regular
Posts: 142
Joined: 02 Sep 2013 20:17
Location: Netherlands

Re: Displaying integers in a text object?

Post by MrCorba »

You'll have to concatenate the integer and an empty string and this will turn the value into a string. Like this

Code: Select all

decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', '' + val);
It's not optimal but once you know it it's easy to work around it.

Ah damn, oldgearguy beat me to it
"Having no silence in music is like having no black or white in a painting" - Brian Eno
https://soundcloud.com/mrcorba
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Re: Displaying integers in a text object?

Post by GV1 »

oldgearguy wrote:try this:

Code: Select all

decl val = 9;
setattribute(OctaveLabel.octaveValue, 'content', ''+val);

:shock:

outside the box man, outside the box.
I tried that, it didn't work. Really odd. Unless this is only available in newer updates.
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Re: Displaying integers in a text object?

Post by GV1 »

Only other thing I can think of is use a monitor object, make it transparent and put a black empty text object over monitor. Urgh. Hackish if I have to do that. :lol:
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Displaying integers in a text object?

Post by oldgearguy »

GV1 wrote:
oldgearguy wrote:try this:
I tried that, it didn't work. Really odd. Unless this is only available in newer updates.
I forgot you were on original hardware. Does this work?

Code: Select all

decl val={0x39};
setattribute (Label, 'content', arraytostring(val));
If it does, that means you'll have to do more math to add 0x30 to each decimal place and do the division to break down the raw number.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: Displaying integers in a text object?

Post by oldgearguy »

Here's a quick and dirty way to take a number and array-ify it. You'll probably want to make it more elegant, but you get the idea:

Code: Select all

decl val, tmp;
decl num=4819, i=0, remain;

while (num > 0) {
   remain = num % 10;
   tmp[i++] = remain + 0x30;
   num = floor(num / 10);
}
i--;

while (i >= 0)
   val[sizeof(tmp) - i - 1] = tmp[i--];

setattribute (Label, 'content', arraytostring(val));
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Re: Displaying integers in a text object?

Post by GV1 »

Thanks. I was thinking about doing this. Will give it a shot tomorrow.
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Re: Displaying integers in a text object?

Post by GV1 »

Testing now. I'm not sure how I can make it more elegant except to contain it in a function ... that's a solid solution to be honest.
GV1
Newbie
Posts: 38
Joined: 03 Jan 2012 19:33

Re: Displaying integers in a text object?

Post by GV1 »

Works :)

Code: Select all

setattribute(testTxt, 'content', Helpers.intToString(49));
Thanks!
Post Reply