I’m writing a script that has functionality based on subtool names, and was wondering about comparison operators as they relate to string variables.
In Javascript (which is the language I’m most comfortable in), you can compare two string variables using an == operator, like so:
var str1 = "match";
var str2 = "match";
if (str1 == str2) {
//// RETURNS TRUE
console.log("they match");
}
I was wondering if it’s possible to do the same with ZScript - I had a look at the documentation, but to no avail. I also had a go with this script:
[VarDef, Str1, "they"]
[VarDef, Str2, "they"]
[If, Str1==Str2,
[VarSet, Str2, "match"]
[Note, [StrMerge, Str1, Str2]]
, //else
[Note, "no match"]
]
///////////////////RETURNS TRUE (fine)
The script above always returns true, which is fine, but when I change the value of Str2 to a value that is not the same as Str1 (and therefore should return false), it still always returns as true.
[VarDef, Str1, "they"]
[VarDef, Str2, "don't match"]
[If, Str1==Str2,
[VarSet, Str2, "match"]
[Note, [StrMerge, Str1, Str2]]
, //else
[Note, "no match"]
]
///////////////////ALSO RETURNS TRUE (not fine)
I can’t imagine a scripting language would be made without the ability to compare strings, so was wondering if anyone could offer some insight on what I might be missing here.
Thanks in advance!