It is currently March 28th, 2024, 11:32 am

Understanding Ifmatch

Get help with creating, editing & fixing problems with skins
ms310
Posts: 225
Joined: April 1st, 2015, 7:16 am

Understanding Ifmatch

Post by ms310 »

Hi there - I have stumbled upon some code and I would like to know how it works.

Code: Select all

[MeasureCurrent]
Measure=Plugin
Plugin=WebParser
Url=https://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#
RegExp="(?siU)<head>.*<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<icon>(.*)</icon>"
UpdateRate=900
StringIndex=6
IfMatch=(?si)0
IfMatchAction=[!SetVariable FontColor "133,133,133"]
IfMatch2=(?si)1|2|3|4|17|35|
IfMatchAction2=[!SetVariable FontColor "34,2,101"]
IfMatch3=(?si)5|6|7|8|9|10|11|12|18
IfMatchAction3=[!SetVariable FontColor "93,106,123"]
IfMatch4=(?si)13|14|15|16|25|42|43
IfMatchAction4=[!SetVariable FontColor "226,223,232"]
IfMatch5=(?si)19|20|21|22|23|24
IfMatchAction5=[!SetVariable FontColor "151,147,159"]
IfMatch6=(?si)26|44
IfMatchAction6=[!SetVariable FontColor "58,146,255"]
IfMatch7=(?si)28|29|33|45
IfMatchAction7=[!SetVariable FontColor "44,102,174"]
IfMatch8=(?si)31
IfMatchAction8=[!SetVariable FontColor "3,55,98"]
IfMatch9=(?si)30|32|34|37|38|39|40|41
IfMatchAction9=[!SetVariable FontColor "241,154,16"]
I get that based on some condition set the variable FontColor. What confuses me is the Match statements - what is being compared? Thanks for the help!
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

Post by ikarus1969 »

IfMatch compares/matches the result of its measure. In this case the, because it's a Webparser measure, the resulting string is set by the StringIndex-option.
Here StringIndex=6 means that the IfMatch-options match against the sixth capture: the icon-number.
Depending on the icon-number it sets the FontColor used elsewhere.

e.g. for icon numbers 1, 2, 3, 4, 17 or 35 it sets the FontColor to "34,2,101" (IfMatch2)

docu: IfMatchActions

edit: a capture is basially something sourrounded by "(" and ")" (if not escaped by a back-slash). What i use as a reference to regular-expressions is https://www.regular-expressions.info/, but there are tons of sites dealing with regular-expressions...
ms310
Posts: 225
Joined: April 1st, 2015, 7:16 am

Re: Understanding Ifmatch

Post by ms310 »

ikarus1969 wrote: May 14th, 2019, 5:12 am IfMatch compares/matches the result of its measure. In this case the, because it's a Webparser measure, the resulting string is set by the StringIndex-option.
Here StringIndex=6 means that the IfMatch-options match against the sixth capture: the icon-number.
Depending on the icon-number it sets the FontColor used elsewhere.

e.g. for icon numbers 1, 2, 3, 4, 17 or 35 it sets the FontColor to "34,2,101" (IfMatch2)

docu: IfMatchActions

edit: a capture is basially something sourrounded by "(" and ")" (if not escaped by a back-slash). What i use as a reference to regular-expressions is https://www.regular-expressions.info/, but there are tons of sites dealing with regular-expressions...
AHHHHHHHH! Thank you so very much! That makes a lot of sense!
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

Post by ikarus1969 »

Glad to help!
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Understanding Ifmatch

Post by balala »

Just note one more: although the IfConditions are entirely numeric and you can't use them to compare strings, in a such case when the measure returns number, IfConditions also can be used. I don't say it would have any advantage in front of IfMatch, probably it doesn1t have, just to know the possibility, here is another solution to the same problem:

Code: Select all

[MeasureCurrent]
Measure=WebParser
Url=https://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=#Unit#
RegExp=(?siU)<head>.*<ut>(.*)</ut>.*<dnam>(.*)</dnam>.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<icon>(.*)</icon>
UpdateRate=900
StringIndex=6
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!SetVariable FontColor "133,133,133"]
IfCondition2=(((#CURRENTSECTION#>=1)&&(#CURRENTSECTION#<=4))||(#CURRENTSECTION#=17)||(#CURRENTSECTION#=35))
IfTrueAction2=[!SetVariable FontColor "34,2,101"]
IfCondition3=(((#CURRENTSECTION#>=5)&&(#CURRENTSECTION#<=12))||(#CURRENTSECTION#=18))
IfTrueAction3=[!SetVariable FontColor "93,106,123"]
IfCondition4=(((#CURRENTSECTION#>=13)&&(#CURRENTSECTION#<=16))||(#CURRENTSECTION#=25)||(#CURRENTSECTION#=42)||(#CURRENTSECTION#=43))
IfTrueAction4=[!SetVariable FontColor "226,223,232"]
IfCondition5=((#CURRENTSECTION#>=19)&&(#CURRENTSECTION#<=24))
IfTrueAction5=[!SetVariable FontColor "151,147,159"]
IfCondition6=((#CURRENTSECTION#=26)||(#CURRENTSECTION#=44))
IfTrueAction6=[!SetVariable FontColor "58,146,255"]
IfCondition7=((#CURRENTSECTION#=28)||(#CURRENTSECTION#=29)||(#CURRENTSECTION#=33)||(#CURRENTSECTION#=45))
IfTrueAction7=[!SetVariable FontColor "44,102,174"]
IfCondition8=(#CURRENTSECTION#=31)
IfTrueAction8=[!SetVariable FontColor "3,55,98"]
IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#>=37)&&(#CURRENTSECTION#<=41)))
IfTrueAction9=[!SetVariable FontColor "241,154,16"]
No IfMatches in this case.
Again, probably this solution has no advantages in front of the solution with IfMatch, it's just another approach of the same problem.
Note that in the above (re)posted measure I: EDIT: Fixed this code, after ikarus1969 found a mistake in the originally posted one. Thanks ikarus1969 and sorry for my mistake.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Understanding Ifmatch

Post by ikarus1969 »

balala wrote: May 14th, 2019, 7:07 am

Code: Select all

IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#=37)||(#CURRENTSECTION#<=41)))
IfTrueAction9=[!SetVariable FontColor "241,154,16"]
Wouldn't the only Color be "241, 154, 16" because of your IfCondition9?
There is "...||(#CURRENTSECTION#<=41)" without combining it with the lower value "37" correctly with an "and"-condition.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Understanding Ifmatch

Post by balala »

ikarus1969 wrote: May 14th, 2019, 7:24 am Wouldn't the only Color be "241, 154, 16" because of your IfCondition9?
There is "...||(#CURRENTSECTION#<=41)" without combining it with the lower value "37" correctly with an "and"-condition.
OOPS, you're absolutely right. My mistake. Correctly IfCondition9 is: IfCondition9=((#CURRENTSECTION#=30)||(#CURRENTSECTION#=32)||(#CURRENTSECTION#=34)||((#CURRENTSECTION#>=37)&&(#CURRENTSECTION#<=41))).
I fixed the code I've posted above as well.

Sorry for my mistake.
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: Understanding Ifmatch

Post by nikko »

hello. can someone tell me will this work or not? i do not know is this all correct. thanks in advance.

Code: Select all

[Variables]
Signs=XYZ

[msSigns]
Measure=String
String=#Signs#
IfMatch=X
IfMatchAction=[!ShowMeter "mtSign1"][!UpdateMeter "mtSign1"]
IfNotMatchAction=[!HideMeter "mtSign1"][!UpdateMeter "mtSign1"]
IfMatch2=Y
IfMatchAction2=[!ShowMeter "mtSign2"][!UpdateMeter "mtSign2"]
IfNotMatchAction2=[!HideMeter "mtSign2"][!UpdateMeter "mtSign2"]
IfMatch3=Z
IfMatchAction3=[!ShowMeter "mtSign3"][!UpdateMeter "mtSign3"]
IfNotMatchAction3=[!HideMeter "mtSign3"][!UpdateMeter "mtSign3"]
DynamicVariables=1

[mtSign1]
...

[mtSign2]
...

[mtSign3]
...
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Understanding Ifmatch

Post by SilverAzide »

nikko wrote: December 10th, 2020, 4:33 pm hello. can someone tell me will this work or not? i do not know is this all correct. thanks in advance.
Sure, it will work, but it is not clear what you are trying to do. If your intent is to have every match fail and fire all 3 of the IfNotMatchAction cases, then it should work great. :)

IfMatch matches exactly (the way you have it written), so since "XYZ" isn't exactly "X", "Y", or "Z", then all the "not" matches will fire. If you want to match any part of the string, then you need to adjust your IfMatch expression, like so:

Code: Select all

IfMatch=.*X.*
...
IfMatch2=.*Y.*
...
IfMatch3=.*Z.*
In this case, all 3 of the IfMatchActions will fire since the "XYZ" string contains an X, a Y, and a Z somewhere in the string.

More info here in the manual:
https://docs.rainmeter.net/manual/measures/general-options/ifmatchactions/
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Understanding Ifmatch

Post by balala »

nikko wrote: December 10th, 2020, 4:33 pm hello. can someone tell me will this work or not? i do not know is this all correct. thanks in advance.
There always is an extremely simple way to find out if such a code does or doesn't work: you have to give it a try and you'll find out by yourself. As SilverAzide siad, the posted code does definitely work, however unfortunately he had a small mistake (see below).
Post Reply