String functions - trying to get the best of them

Discuss Lemur and share techniques.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

String functions - trying to get the best of them

Post by Softcore »

So, lets say we have some custom expressions named Pr0, Pr1, Pr2, Pr3, Pr4...Pr15 inside a container.....

I cant "find" them to perform scripts on them by:

Code: Select all

findobject('Pr'+i)
???

I thought I could....What am I missing?
I thought, ah well expressions are not objects per se, so I then tried

Code: Select all

decl list;
for (i=0;i<16;i++) {
list[i]='Pr'+i;
}
But still after that I cant fill Pr0, for example by going list[0]={1,2,32,1};

Any thoughts?
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: String functions - trying to get the best of them

Post by oldgearguy »

I have been using Monitor objects for this very reason. I never have been able to indirectly reference variables like that.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: String functions - trying to get the best of them

Post by Softcore »

Hear ya! I thought that now with the string functions I might be able to pull it off!

Although, now that I look what I was trying to do with a fresh eye it makes sense that it wouldnt work. I think we need to request a getexpression() function for containers or the unification of "object" (actual reference of an object) with "name" (the name of an object described with string)


Thanks!

edit: OK, I getexpression(container, k) with a custom expression and it works...This will probably do what I want it to do.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: String functions - trying to get the best of them

Post by oldgearguy »

The other reason I have been using Monitor objects is that you can instantiate them to longer arrays than regular variables inside the Lemur Windows Editor. The way the editor counts bytes in an array is different between the two, although it shouldn't be different.
Blaakk
Newbie
Posts: 13
Joined: 19 Jan 2014 19:39

Re: String functions - trying to get the best of them

Post by Blaakk »

Mmm, very interesting. Cheers!
Mike-L
Newbie
Posts: 9
Joined: 27 Feb 2014 13:17

Re: String functions - trying to get the best of them

Post by Mike-L »

I saw this thread and think I'm having a similar problem. Please bear with me as I am very much a newbie when it comes to both coding & lemur :)

I have a set of vectors inside a container e.g s1,s2,s3,s4,s5....s16 .
What i want to do is change every [n] element across some of these vectors, for example,i may want to change s1[2],s5[2],s9[2],s13[2] all to the same value.How do I reference 's' + 'x' and [n] ,where 's' is the vector's name ,'x' is the numerical suffix of the vector's name and [n] is the element in the vector I want to change?
Is this possible?

Thanks!
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: String functions - trying to get the best of them

Post by Softcore »

Not sure I get the question Mike-L....

If your vector is a string i.e

v = {'s1','s2'........'s16"};

Then by simply typing in a script

v[1] = 's23'

will change 's2' to 's23'

Is this what you are asking?
Mike-L
Newbie
Posts: 9
Joined: 27 Feb 2014 13:17

Re: String functions - trying to get the best of them

Post by Mike-L »

Thanks Softcore,

No I have a set of vectors:
vector 1:0,0,0,0,0,0,0
vector2:0,0,0,0,0,0,0
vector3:0,0,0,0,0,0,0
vector4:0,0,0,0,0,0,0
etc ...
I would like to be able to change the nth element of all chosen vectors, in a repetitve way. In other words a script that will refer to Vector 'X' [n] and then I can repeat through the script changing the X value to address the different vectors. So if X starts as 1, increasese in increments by 1 and position [2] is assigned a value of 4 the final product would be:
vector 1:0,0,4,0,0,0,0
vector2:0,0,4,0,0,0,0
vector3:0,0,4,0,0,0,0
vector4:0,0,4,0,0,0,0

I know that I can use loops to repeat through an array changing values, but I don't know how or if you can loop through different expressions/vectors.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: String functions - trying to get the best of them

Post by Softcore »

Ooooh that was a bit tricky! Here's one way to pull it off! Not sure its the best one - I only fiddled with it for 10 minutes. use the Pads to change an nth position of all vectors. The monitors display the 4 example vectors.
Attachments
repeatedFunctionOnVectors.jzml
(6.36 KiB) Downloaded 68 times
Mike-L
Newbie
Posts: 9
Joined: 27 Feb 2014 13:17

Re: String functions - trying to get the best of them

Post by Mike-L »

ah! thank you so much for the help Softcore. I'll have a look at what you've done.
It seems im using a lot of trial and error with my scripting at the moment. Im especially getting knotted up with loops and making sure the braces are in the right place.
Post Reply