# Comparing text variables



## Thonex (Dec 11, 2008)

Hi guys,

I'm drawing a blank. Please tell me this is possible... Is there a way to compare 1 text variable with another?

For example:

*on init*
``*declare* @Text1
``*declare* @Text2
``@Text1 := "Dog"
``@Text2 := "Dog"
``*declare* ui_label $Result (1,1)
``
``*if* (@Text1 = @Text2)
````set_text ($Result, "they match")
``*else*
````set_text ($Result, "they don't match")
``*end if*
``
*end on*


I get: *"ERROR (line 7) ; boolean expression expected"*

Is there a way to achieve what I want in KSP?

Thanks,

T


----------



## gregjazz (Dec 11, 2008)

I don't think you can compare strings, unless it's a group name.


----------



## kotori (Dec 11, 2008)

Greg is right. Why would you like to do this anyway?


----------



## Hans Adamson (Dec 11, 2008)

Then maybe if you create two dummy groups, rename them to the names you want to compare, and then compare the group names. ? (If it's possible to rename a group from within the script, that is.)

Or name the two dummy groups: @Text1 and @Text2, and then compare the group names. Probablly won't work - juat trying to be creative here... 8)


----------



## Thonex (Dec 11, 2008)

kotori @ Thu Dec 11 said:


> Greg is right. Why would you like to do this anyway?



Actually, it would be to track group names. For example, my script tries to find a group "Stac 3". but if "stac 3" isn't in the instrument I get an error. I thought there was a way to have KSP ignore errors... no?

Anyway. how did Big Bob search and find Groups with "RT" in them?

Thanks for any help.

Cheers,

T


----------



## Big Bob (Dec 11, 2008)

> Anyway. how did Big Bob search and find Groups with "RT" in them?



Actually I didn't but I think Nils did a long time ago. If I remember correctly he did it by comparing the group name against several different variants such as xxRT, xRTx, RTxx, etc. I'm sure Nils will remember this better than I do :oops: This of course was before the ep method of identifying release groups. 

Another way we have used in the past to kind of work-around the very limited set of string functions is to sort of 'roll your own' character encoding and then store the strings as arrays of numbers. Then you can use the *array_equal *function to compare such 'strings'.

Incidentally Nils, shouldn't the function definition for *array_equal *in your editor be declared as type boolean? ie


```
array_equal(<array-variable>,<array-variable>):boolean
```

as opposed to :integer as it is now? I think the KSP treats this seldom used function the same as *in_range*, no?

God Bless,

Bob


----------



## Thonex (Dec 11, 2008)

Thanks Bob,



Big Bob @ Thu Dec 11 said:


> If I remember correctly he did it by comparing the group name against several different variants such as xxRT, xRTx, RTxx, etc. I'm sure Nils will remember this better than I do :oops: This of course was before the ep method of identifying release groups.



I'm sure you don't mean that "x" in xxRT would be a wild card... or would it? If so, how is it implemented. Also, I'm guessing there is no way the extract each "letter" from a string and save it to a variable. I'm almost sure that its impossible, but (fortunately) I've been proven wrong so many times. :D 

Cheers,

T


----------



## gmet (Dec 11, 2008)

Andrew,

I think this is the thread to which you are referring:

http://vi-control.net/forum/viewtopic.p ... ght=#60310

Hope it helps,

Justin


----------



## Big Bob (Dec 11, 2008)

Hi Andrew,

The link Justin posted *is* for the thread I was thinking of all right, good show Justin 8) 



> I'm sure you don't mean that "x" in xxRT would be a wild card... or would it? If so, how is it implemented.



You're right Andrew I didn't mean the xx to be taken either literally or as wild cards, it was just my clumsy way to illustrate the gist of the thing. Nils' original posting in the referenced thread should clear the situation up. 



> Also, I'm guessing there is no way the extract each "letter" from a string and save it to a variable. I'm almost sure that its impossible, but (fortunately) I've been proven wrong so many times.



Again, unfortunately, you are correct. There are no string functions to do things like isolate characters, etc. About all one can do with strings (besides displaying them) is to concatenate them. So, you can put them together but you can't reverse the process. Too bad because it would be nice to have a more robust string facility.

In the meantime the only other technique I can suggest (BTW I think this idea also originated with Nils) is numerical encoding of the alphabetic characters so that you can use the array structure and various arithmetic operations to manipulate the strings. This is the basic technique used by the SIPS rename facility for example.

God Bless,

Bob


----------



## Thonex (Dec 11, 2008)

Thanks Justin and Bob,

I agree... attaching numeric values to characters is the way to go to keep track of tings. 

I'll have to look closely at Nil's work 8) and see if I can even understand it :lol: 

Thanks guys,

T


----------



## kotori (Dec 11, 2008)

Here's a summary of how to do it for group names:

The find_group(<name>) returns the index of the group with the given name or 0 if it is not found. It's of course silly that 0 is used (rather than say -1) since 0 could also be the index of the first group. However, if you are sure that the group you are searching for won't be the group with index 0 you can compare two group names like this:

Instead of "if name1 = name2" which doesn't work since one cannot compare strings you write:

```
index1 := find_group(name1)
index2 := find_group(name2)
if index1 = index2 and index1 # 0  { if name1 = name2 (won't work for first group) }
   ...
end if
```

Even if you know the group index you would still need to run find_group(group_name(index)) in case there's a possibility that multiple groups have the same name. The find_group function would then find the first group and the comparison would always work (except for the first group of course).

Btw. if the purpose is to find release trigger groups, why not just use the new $ENGINE_PAR_RELEASE_TRIGGER for that?

Cheers,
Nils


----------



## Big Bob (Dec 12, 2008)

Hi Nils,

Did you perchance miss this part of my prior post? (since you didn't comment on it)


> Incidentally Nils, shouldn't the function definition for array_equal in your editor be declared as type boolean? ie
> 
> 
> Code:
> ...



It's a small thing but you may want to correct it for your next release.



> Btw. if the purpose is to find release trigger groups, why not just use the new $ENGINE_PAR_RELEASE_TRIGGER for that?



This of course is precisely what I meant by the ep method in the last sentence below.



> Actually I didn't but I think Nils did a long time ago. If I remember correctly he did it by comparing the group name against several different variants such as xxRT, xRTx, RTxx, etc. I'm sure Nils will remember this better than I do This of course was before the ep method of identifying release groups.



God Bless,
Bob


----------



## Thonex (Dec 12, 2008)

Thanks Nils!!!!

I'll try it out.




kotori @ Fri Dec 12 said:


> Btw. if the purpose is to find release trigger groups, why not just use the new $ENGINE_PAR_RELEASE_TRIGGER for that?
> 
> Cheers,
> Nils



Oh... heh... because all my RTs are scripted and don't use Kontakt's Release Trigger engine. :lol: 


And you are so right with regards to KSP returning "0" when no group index is not found.

Thanks again.

T


----------



## Big Bob (Dec 12, 2008)

> Oh... heh... because all my RTs are scripted and don't use Kontakt's Release Trigger engine.



Hi Andrew,

Here's a thought that might be useful. If you have scripted all release sample triggering then why not disable Kontakt's release handling with your script(s) and then you will be free to use the Release Trigger buttons any way you want without direct effect. Therefore, you can set them as annotation flags for groups you want to identify and of course your scripts can then read them via the ep. Since I'm not really sure what you are shooting for, this idea may be totally useless and if so, just throw it in trash can :lol: 

God Bless,

Bob


----------



## Thonex (Dec 12, 2008)

Big Bob @ Fri Dec 12 said:


> > Oh... heh... because all my RTs are scripted and don't use Kontakt's Release Trigger engine.
> 
> 
> 
> ...




ooooohh.... I like it!!!! So, disable RT in K2... and then "flag" the RTs with Kontakt's inactive RT buttons and then use the $ENGINE_PAR_RELEASE_TRIGGER to locate them. 

Very clever!!! I think I 'll try that out!!!!

Cheers,

T


----------



## kotori (Dec 12, 2008)

Big Bob @ Thu Dec 11 said:


> Incidentally Nils, shouldn't the function definition for *array_equal *in your editor be declared as type boolean? ie


Yes, absolutely. Good catch! The fix will be included in the next version.

If anyone wants to use this function (I myself have never had the need for it) in the meantime, it's fully possible to manually edit the ksp_util.txt file in the installation folder of KScript Editor.

Cheers,
Nils


----------



## Nickie Fønshauge (Dec 12, 2008)

Big Bob @ 12th December 2008 said:


> why not disable Kontakt's release handling with your script(s) and then you will be free to use the Release Trigger buttons any way you want without direct effect. Therefore, you can set them as annotation flags for groups you want to identify and of course your scripts can then read them via the ep.


Excellent idea, Bob. 8) [schild=14 fontcolor=191970 shadowcolor=EE82EE shieldshadow=1]Cudos![/schild]


----------



## Big Bob (Dec 12, 2008)

Hey thanks Nickie, long time no see :D .

BTW is the Cudos (with a 'C') intended to 'break' the Kontakt 'K' phobia? :roll: 

God Bless,

Bob


----------



## polypx (Dec 13, 2008)

I know this is completely off-topic, but I like words, and it also reminds me of "cadeau".  

According to wikipedia tho, Kudos is from Greek and has been used in English for some time. Which is strange, because I've only noticed it in the last ten years or so.

http://en.wikipedia.org/wiki/Kudos


Ok... back to text variables.


----------



## Big Bob (Dec 13, 2008)

Nothing is Off-Topic when you're having fun :lol:


----------

