It is currently April 23rd, 2024, 9:48 am

IfMatch always returns false in Calc measure?

Get help with creating, editing & fixing problems with skins
User avatar
Christopher Robin
Posts: 14
Joined: January 20th, 2020, 3:55 pm

IfMatch always returns false in Calc measure?

Post by Christopher Robin »

Every time I think I'm beginning to grasp what i'm doing, I smack into a wall...

This is a minor point, and there are ways around it, so I should just do one of those and move on, but it's frustrating me to tears because I just don't understand. And every seemingly relevant forum post I can find turns out to actually be a case of someone trying to do math in an IfMatch or use strings in an IfCondition, or something else that makes the answer tangential to what I'm looking for.

Test skin:

Code: Select all

[Variables]
TestVariable=5

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
IfMatch=^15$
IfMatchAction=[!SetVariable duck "Joe"]
IfNotMatchAction=[!SetVariable duck "Charlie"]

[Ducky]
Meter=String
FontSize=24
FontColor=255,255,255
SolidColor=0,0,0
Text=The duck is named #duck#.
DynamicVariables=1
Log: number value of DuckTest = 15; string value of DuckTest ALSO = 15
Output: "The duck is named Charlie".

Variation 1: maybe the problem is that 15 is a number? That doesn't make much sense, since the measure has a string value; it just happens to be the symbols which represent its number value. Maybe IfMatch can handle an actual word?

Code: Select all

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
Substitute:"15":"Bob"
IfMatch=^Bob$
IfMatchAction=[!SetVariable duck "Joe"]
IfNotMatchAction=[!SetVariable duck "Charlie"]
Log: DuckTest string value = Bob
Output: The duck is named Charlie.

Variation 2: um, okay, so maybe DuckTest isn't really outputting what I think it is? Let's see what it comes out to as a variable.

Code: Select all

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
Substitute:"15":"Bob"
IfMatch=^Bob$
IfMatchAction=[!SetVariable duck "Joe"]
IfNotMatchAction=[!SetVariable duck "[DuckTest]"]
Log: DuckTest string value, still = Bob
Output: The duck is named Bob.

Wh...what? WHAT? "Does DuckTest match 'Bob'?" "No, it doesn't." "In your return-false message, what does DuckTest equal?" "'Bob'."

Note that these, to put it really mildly, are not the only variations I've tried, and I've gone through every permutation of syntax and structural logic as well: with the ^$ and without, with quotes around everything and around nothing, with #TestVariable# as a variable and as a separate measure, eliminating #TestVariable# and just putting a plain number in the Formula field... nothing names the stupid duck Joe.

What is happening? The closest I can come to an answer is that IfMatch can't access the string value of a Calc measure from inside it, which is to say that IfMatch, basically, cannot be used in a Calc measure unless you need something to return false on all conditions. If that's the case, then the first sentence of the IfMatchActions manual page needs to be corrected. If it's not the case, then... I'm just completely lost. There's some kind of magic smoke inside Rainmeter and it's beyond me; all these black boxes are really starting to wear down my will to continue.

Obviously IfCondition can be used instead, but the prospect of putting "(MeasureName = 2) || (MeasureName = 3) || (MeasureName = 5)..." where "2|3|5|..." has no apparent reason not to work is downright nauseating. My actual temporary solution is to create a second String measure to process the results of the Calc, but that's annoying because I have to decide which one gets the original, usefully descriptive name and what to call the second one. Most importantly, neither solution gets me any closer to understanding WHAT IS THE PROBLEM?

On most forums I wouldn't feel a need to add this, but since you guys respond so startlingly fast, I'm just about to head out and won't be back to reply for a few hours. Thanks in advance for your help, even though there's about a 90% chance that it's going to reveal that I've misjudged the significance of some phrase buried in the manual and make me feel like a complete idiot. :oops:
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch always returns false in Calc measure?

Post by jsmorley »

The problem is the "order" in which things are done in Rainmeter. The IfMatch is being done before the Substitute. If you do something like this, it will work:

Code: Select all

[Variables]
TestVariable=5

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
Substitute="15":"Bob"

[DuckCompare]
Measure=String
String=[DuckTest]
DynamicVariables=1
IfMatch=Bob
IfMatchAction=[!SetVariable duck "Bob"]
IfNotMatchAction=[!SetVariable duck "Charlie"]

[Ducky]
Meter=String
FontSize=24
FontColor=255,255,255
SolidColor=0,0,0
Text=The duck is named #duck#.
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch always returns false in Calc measure?

Post by jsmorley »

Now mind you, it feels like this SHOULD work:

Code: Select all

[Variables]
TestVariable=5

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
IfMatch=^15$
IfMatchAction=[!SetVariable duck "Joe"]
IfNotMatchAction=[!SetVariable duck "Charlie"]

[Ducky]
Meter=String
FontSize=24
FontColor=255,255,255
SolidColor=0,0,0
Text=The duck is named #duck#.
DynamicVariables=1
But it does not. I need to dig a bit deeper, but it looks like IfMatch just doesn't work and play well with Calc measures, even though at the end of the day they do have a "numeric" string value. I'm pretty sure I'm going to find that the "string" value is being shoehorned in after the fact, and we still have the "order" issue. The same solution as above will fix it.

If I am right, then I agree that we either need to fix this, or correct the manual.
User avatar
Christopher Robin
Posts: 14
Joined: January 20th, 2020, 3:55 pm

Re: IfMatch always returns false in Calc measure?

Post by Christopher Robin »

Okay, so certain people who insisted I get up early are not now, themselves, ready to go... sheesh.
I need to dig a bit deeper, but it looks like IfMatch just doesn't work and play well with Calc measures, even though at the end of the day they do have a "numeric" string value. I'm pretty sure I'm going to find that the "string" value is being shoehorned in after the fact, and we still have the "order" issue.
At least that means I'm not totally stupid or losing my mind, if you also feel that it ought to work that way. It seems worthwhile to point out that

Code: Select all

[DuckTest]
Measure=Calc
Formula=15
IfMatch=^15$
IfMatchAction=[!SetVariable duck "Joe"]
IfNotMatchAction=[!SetVariable duck "Charlie"]
Where no calculations or substitutions are being done, doesn't work either.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch always returns false in Calc measure?

Post by jsmorley »

Of course this makes a WHOLE lot more sense...

Code: Select all

[Variables]
TestVariable=5

[DuckTest]
Measure=Calc
Formula=3 * #TestVariable#
IfCondition=DuckTest = 15
IfTrueAction=[!SetVariable duck "Joe"]
IfFalseAction=[!SetVariable duck "Charlie"]

[Ducky]
Meter=String
FontSize=24
FontColor=255,255,255
SolidColor=0,0,0
Text=The duck is named #duck#.
DynamicVariables=1
I mean, shoulda, woulda, coulda aside, IfMatch is meant for "strings" and IfCondition is meant for "numbers". Right tool for the right job, yes?
User avatar
Christopher Robin
Posts: 14
Joined: January 20th, 2020, 3:55 pm

Re: IfMatch always returns false in Calc measure?

Post by Christopher Robin »

jsmorley wrote: March 15th, 2020, 2:27 pm I mean, shoulda, woulda, coulda aside, IfMatch is meant for "strings" and IfCondition is meant for "numbers". Right tool for the right job, yes?
Yeah... my actual solution is to use a second, String measure to run the IfMatch because "2|3|5" is so much tighter than "MeasureName = 2 || MeasureName = 3 || MeasureName = 5".

In my actual use case, the Formula is a nested if-conditional that outputs one of six possibilities; after that, the six outcomes never need to be treated as numbers again. If I didn't need to react to those outcomes in groups that aren't related to their numerical values (that is to say, "2,3,5,6" is one response group, "6,1,2" is another, for instance), or if I needed to treat the outcomes as numbers, then definitely IfConditions would be the better tool.

I do agree that in almost every case, there shouldn't be a need to use IfMatch in a Calc measure, but that doesn't address the question of whether doing so is even possible.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: IfMatch always returns false in Calc measure?

Post by jsmorley »

Well, it seems to me that the answer is that IfMatch just doesn't work on Calc measures. I'm not sure that was really even considered when it was designed.
User avatar
Christopher Robin
Posts: 14
Joined: January 20th, 2020, 3:55 pm

Re: IfMatch always returns false in Calc measure?

Post by Christopher Robin »

That's cool then. What was driving me crazy was not knowing whether I was missing something or misunderstanding.
User avatar
Brian
Developer
Posts: 2681
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: IfMatch always returns false in Calc measure?

Post by Brian »

Sorry about being late to the party.

This *might* be bug with IfMatch, we will have to look into backwards compatibility issues that might arise with "fixing" this.

[Technical_details]
IfMatch is specifically designed to match against the string value of the measure. The problem is, some measures do not really have a string value. Calc is one of these measures since it always resolves to a number.

In other parts of Rainmeter when the string value is needed and there is no string value, we convert the number value to a string. IfMatch doesn't do this conversion automatically.
[/Technical_details]

Like jsmorley mentioned above, IfConditions are a better fit for this or an extra string measure that automatically performs the conversion.

-Brian
User avatar
Yincognito
Rainmeter Sage
Posts: 7148
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: IfMatch always returns false in Calc measure?

Post by Yincognito »

Brian wrote: March 17th, 2020, 4:42 am Sorry about being late to the party.

This *might* be bug with IfMatch, we will have to look into backwards compatibility issues that might arise with "fixing" this.

[Technical_details]
IfMatch is specifically designed to match against the string value of the measure. The problem is, some measures do not really have a string value. Calc is one of these measures since it always resolves to a number.

In other parts of Rainmeter when the string value is needed and there is no string value, we convert the number value to a string. IfMatch doesn't do this conversion automatically.
[/Technical_details]

Like jsmorley mentioned above, IfConditions are a better fit for this or an extra string measure that automatically performs the conversion.

-Brian
I'm not sure if what you said is connected to my experiences here (about measures that have a string value of "" behaving differently than other measures in regard to IfMatch and Substitute), but just throwing this here as well, just for your awareness.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth