[solved] comparing strings

Discuss Lemur and share techniques.
Post Reply
Anton
Regular
Posts:75
Joined:08 Dec 2011 12:36
[solved] comparing strings

Post by Anton » 04 Nov 2012 07:31

hi,
I have an incoming stream of names on an OSC adress. I would like to know if the last 2 names received are the same.
I wrote the following code to find that out:

Code: Select all

decl i;
decl z;
i= (number++)%2; //modulo between 0 and 1 everytime a resource is changed.
z[i]=OSC_ARGS; //put current name in array
point=diff(z);
point is a variable that a monitor object can read.
Now when I put in the same string twice in a row I get a point is {0, "string"} however, if i then give the string a third time, it gives "string". Also if i change to another name as input the results stays the same, the diff is always {0, "string"} or {string}.

Anybody tried diff'ing strings before?
Last edited by Anton on 04 Nov 2012 18:41, edited 1 time in total.

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: comparing strings in an array

Post by Macciza » 04 Nov 2012 13:21

Hi
Diff does not work the way you are thinking - check the manual it is a vectorial function . . .

But it's not that complex really, try this . . .

// decl externally - last_msg Add Pads for full effect
decl msg=OSC_ARGS[0];

if(last_msg==msg){ // See if last_msg equals current msg
Pads2.x=1}; //Do Something . . .
else{
Pads2.x=0;}; //Do Something else . . .

last_msg=OSC_ARGS[0]; //Then store current message to last_msg to compare next time round

Cheers
MM
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]

Anton
Regular
Posts:75
Joined:08 Dec 2011 12:36

Re: comparing strings in an array

Post by Anton » 04 Nov 2012 18:41

ofcourse. Thanks Macciza.

Post Reply