It is currently March 29th, 2024, 12:48 pm

Understanding Ifmatch

Get help with creating, editing & fixing problems with skins
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: Understanding Ifmatch

Post by nikko »

Code: Select all

[Variables]
Signs=XYZ
Count=2

[msSigns]
Measure=String
String=#Signs#&#Count#
IfMatch=X1
IfMatchAction=[!SetVariable Meter1 "1"][!WriteKeyValue Variables Meter1 "1" "#@#Vars.inc"]
IfNotMatchAction=[!SetVariable Meter1 "0"][!WriteKeyValue Variables Meter1 "0" "#@#Vars.inc"]
IfMatch2=Y2
IfMatchAction2=[!SetVariable Meter2 "1"][!WriteKeyValue Variables Meter2 "1" "#@#Vars.inc"]
IfNotMatchAction2=[!SetVariable Meter2 "0"][!WriteKeyValue Variables Meter2 "0" "#@#Vars.inc"]
IfMatch3=Z3
IfMatchAction3=[!SetVariable Meter3 "1"][!WriteKeyValue Variables Meter3 "1" "#@#Vars.inc"]
IfNotMatchAction3=[!SetVariable Meter3 "0"][!WriteKeyValue Variables Meter3 "0" "#@#Vars.inc"]
DynamicVariables=1
Count variable can be from 0-3

I want when X1 and so on are matched, to have Meter1 value 1 and so on. But dont work for some reason. :-( Help
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Understanding Ifmatch

Post by jsmorley »

IfMatch uses regular expression.

You will want something like this:

IfMatch=X.*1

So IfMatch X, followed by . any character * any number of times, followed by 1
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: Understanding Ifmatch

Post by nikko »

is something like this possibile?

Code: Select all

[Variables]
Signs=XYZ
Count=2

[msSigns]
Measure=String
String=#Signs#
IfMatch=X & #Count#=2
IfMatchAction=[!SetVariable Meter1 "1"][!WriteKeyValue Variables Meter1 "1" "#@#Vars.inc"]
IfNotMatchAction=[!SetVariable Meter1 "0"][!WriteKeyValue Variables Meter1 "0" "#@#Vars.inc"]
IfMatch2=X & #Count#=5
IfMatchAction2=[!SetVariable Meter2 "1"][!WriteKeyValue Variables Meter2 "1" "#@#Vars.inc"]
IfNotMatchAction2=[!SetVariable Meter2 "0"][!WriteKeyValue Variables Meter2 "0" "#@#Vars.inc"]
IfMatch3=Z & #Count#=21
IfMatchAction3=[!SetVariable Meter3 "1"][!WriteKeyValue Variables Meter3 "1" "#@#Vars.inc"]
IfNotMatchAction3=[!SetVariable Meter3 "0"][!WriteKeyValue Variables Meter3 "0" "#@#Vars.inc"]
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Understanding Ifmatch

Post by jsmorley »

nikko wrote: March 2nd, 2021, 2:58 pm is something like this possibile?

Code: Select all

[Variables]
Signs=XYZ
Count=2

[msSigns]
Measure=String
String=#Signs#
IfMatch=X & #Count#=2
IfMatchAction=[!SetVariable Meter1 "1"][!WriteKeyValue Variables Meter1 "1" "#@#Vars.inc"]
IfNotMatchAction=[!SetVariable Meter1 "0"][!WriteKeyValue Variables Meter1 "0" "#@#Vars.inc"]
IfMatch2=X & #Count#=5
IfMatchAction2=[!SetVariable Meter2 "1"][!WriteKeyValue Variables Meter2 "1" "#@#Vars.inc"]
IfNotMatchAction2=[!SetVariable Meter2 "0"][!WriteKeyValue Variables Meter2 "0" "#@#Vars.inc"]
IfMatch3=Z & #Count#=21
IfMatchAction3=[!SetVariable Meter3 "1"][!WriteKeyValue Variables Meter3 "1" "#@#Vars.inc"]
IfNotMatchAction3=[!SetVariable Meter3 "0"][!WriteKeyValue Variables Meter3 "0" "#@#Vars.inc"]
DynamicVariables=1
Like this:

Code: Select all

[MeasureExample]
Measure=String
String=#Signs# #Count#
IfMatch=^.*X.*\s2$
IfMatchAction=[!Log "X and 2"]
IfNotMatchAction=[!Log "NOT X and 2"]
IfMatch2=^.*X.*\s5$
IfMatchAction2=[!Log "X and 5"]
IfNotMatchAction2=[!Log "NOT X and 5"]
IfMatch3=^.*Z.*\s21$
IfMatchAction3=[!Log "Z and 21"]
IfNotMatchAction3=[!Log "NOT Z and 21"]
DynamicVariables=1
IfMatch only works on the value of the measure it is contained in, and is always a string regular expression. It has no ability to either look at any external value like a #Variable#, nor does it have any ability to do any kind of "equal/less/greater" numeric comparison. IfMatch is NEVER about "is equal to or less than" or anything like that. It is only about "is there a match between the string value of the measure and my regular expression?". It's not about "equal to", but rather "contains".

So what I did was combine the two #Variables# into the one String value of the measure, using a space to separate them. Then I can use a regular expression that looks for X or Y or Z or whatever in the first bit, followed by a space and then look for the numeric value as a string.

So:

IfMatch3=^.*Z.*\s21$

Start at the ^ beginning of the string, then look for a Z with .* zero or more of any characters before and after it, then a \s whitespace character, followed by the numeric string 21, then the $ end of the string.

If you might have spaces in the string variable, then you probably want to use something to separate the two other than a space. Try not to use a reserved character in regular expression, as that just complicates things. Maybe use a ; or : character.
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: Understanding Ifmatch

Post by nikko »

good job jsmorley but i have more Count variables and it is more complicated. sorry i didnt express myself well. is this possibile?

Code: Select all

[Variables]
Signs=XYZ
Count1=0123456789
Count2=0123456789
Count3=0123456789
Count4=0123456789
Count5=0123456789
...

[msSigns]
Measure=String
String=#Signs#
IfMatch=X & #Count1#=2
IfMatchAction=[!SetVariable Meter1 "1"][!WriteKeyValue Variables Meter1 "1" "#@#Vars.inc"]
IfNotMatchAction=[!SetVariable Meter1 "0"][!WriteKeyValue Variables Meter1 "0" "#@#Vars.inc"]
IfMatch2=X & #Count2#=5
IfMatchAction2=[!SetVariable Meter2 "1"][!WriteKeyValue Variables Meter2 "1" "#@#Vars.inc"]
IfNotMatchAction2=[!SetVariable Meter2 "0"][!WriteKeyValue Variables Meter2 "0" "#@#Vars.inc"]
IfMatch3=Z & #Count5#=9
IfMatchAction3=[!SetVariable Meter3 "1"][!WriteKeyValue Variables Meter3 "1" "#@#Vars.inc"]
IfNotMatchAction3=[!SetVariable Meter3 "0"][!WriteKeyValue Variables Meter3 "0" "#@#Vars.inc"]
...
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Understanding Ifmatch

Post by jsmorley »

nikko wrote: March 2nd, 2021, 3:41 pm good job jsmorley but i have more Count variables and it is more complicated. sorry i didnt express myself well. is this possibile?

Code: Select all

[Variables]
Signs=XYZ
Count1=0123456789
Count2=0123456789
Count3=0123456789
Count4=0123456789
Count5=0123456789
...

[msSigns]
Measure=String
String=#Signs#
IfMatch=X & #Count1#=2
IfMatchAction=[!SetVariable Meter1 "1"][!WriteKeyValue Variables Meter1 "1" "#@#Vars.inc"]
IfNotMatchAction=[!SetVariable Meter1 "0"][!WriteKeyValue Variables Meter1 "0" "#@#Vars.inc"]
IfMatch2=X & #Count2#=5
IfMatchAction2=[!SetVariable Meter2 "1"][!WriteKeyValue Variables Meter2 "1" "#@#Vars.inc"]
IfNotMatchAction2=[!SetVariable Meter2 "0"][!WriteKeyValue Variables Meter2 "0" "#@#Vars.inc"]
IfMatch3=Z & #Count5#=9
IfMatchAction3=[!SetVariable Meter3 "1"][!WriteKeyValue Variables Meter3 "1" "#@#Vars.inc"]
IfNotMatchAction3=[!SetVariable Meter3 "0"][!WriteKeyValue Variables Meter3 "0" "#@#Vars.inc"]
...
DynamicVariables=1
Obviously not, as I clearly stated that this IfMatch=X & #Count1#=2 has no meaning in an IfMatch. It's not about "equal", and in any case the IfMatch is ONLY going to be looking at the string value of the measure it is in, which is "XYZ". Those "count" variables are not a factor at all in what you have posted, and nothing is ever "equal to".

You need a more realistic example, so we don't play "bring me a rock", which is my least favorite game...