Page 1 of 1

[solved] comparing strings

Posted: 04 Nov 2012 07:31
by Anton
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?

Re: comparing strings in an array

Posted: 04 Nov 2012 13:21
by Macciza
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

Re: comparing strings in an array

Posted: 04 Nov 2012 18:41
by Anton
ofcourse. Thanks Macciza.