It is currently April 20th, 2024, 6:38 am

Multiple lines as one variable?

General topics related to Rainmeter.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Multiple lines as one variable?

Post by kyriakos876 »

Hello, this is me again with another question, or three to be more accurate.
I was wondering :

1) Is it possible to set a whole Meter,Measure or a section of code, as one variable?
for example instead of writing multiple times:

Code: Select all

[SomeMeter]
Meter=Something

have a variable set as:
SomeVar: [SomeMeter]
Meter=Something
and simply type it like:

Code: Select all

#SomeVar#
As many times as one wants

2)How can I stop a Measure when a condition is true? Like a break command or something.
for example say I have:

Code: Select all

[SomeMeasure]
Measure=Plugin
Plugin=SomePlugin
IfMatch=SomeCondition
IfMatchAction=SomeAction
IfMatch2=SomeCondition
IfMatchAction2=SomeAction
and I want it to stop if the first condition is true. Is this possible?

3)Can I ever have "too many" Conditions in one measure or is it okay if I have for example 100 conditions in one measure? Would it be better/worse/no different, if I break it down to 2 measures of 50 ?
Thanks!
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Multiple lines as one variable?

Post by fonpaolo »

For question #1, I leave it at someone with a knowledge less rusty than mine...

For the other two questions, you can "limit" the measure simply using UpdateDivider=-1 and then "force" the measure on command, for example:
If the measure is already bound to another one, add a OnChangeAction=[!UpdateMeasure MeasureWithIfCondition] to the first one;
If the measure is the only one, then, split it in two measures, the first part retrieving the data from the plugin, the second, maybe using a Calc measure, to verify the IfConditions, using the first measure as source.

You can add as many IfConditions as you want, my experience is up to twelve, but you can add a lot more.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Multiple lines as one variable?

Post by jsmorley »

The answer to the first question is "no", that is not possible. The answer to the second question is that the number of IfCondition / ItMatch options on a measure is in essence unlimited, and there is no advantage in breaking them up into separate measures.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Multiple lines as one variable?

Post by kyriakos876 »

fonpaolo wrote:For question #1, I leave it at someone with a knowledge less rusty than mine...

For the other two questions, you can "limit" the measure simply using UpdateDivider=-1 and then "force" the measure on command, for example:
If the measure is already bound to another one, add a OnChangeAction=[!UpdateMeasure MeasureWithIfCondition] to the first one;
If the measure is the only one, then, split it in two measures, the first part retrieving the data from the plugin, the second, maybe using a Calc measure, to verify the IfConditions, using the first measure as source.

You can add as many IfConditions as you want, my experience is up to twelve, but you can add a lot more.
I want the measure to update every, say 1 second, but stop if one condition is true. Stop. Like, not even check the other Condition in the same Skin Update. There is no other measure/meter triggering the Measure so setting UpdateDivider=-1 would simply make it update once.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Multiple lines as one variable?

Post by kyriakos876 »

jsmorley wrote:The answer to the first question is "no", that is not possible. The answer to the second question is that the number of IfCondition / ItMatch options on a measure is in essence unlimited, and there is no advantage in breaking them up into separate measures.
I think you made a mistake there. You answered the 3rd question as the second but you never answered the 2nd. The second is
How (If) can I stop a Measure when a condition is true? Like a break command or something.
Example:

Code: Select all

[Rainmeter]
Update=1000
This will update all the measures every 1 second (if no other update bang is involved)
So if I have a Measure with 5 conditions it will check all 5 of them on every update.
How can I make it check only the ones needed until it finds a match? For example the 3rd condition is true so it won't check the 4th or 5th.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Multiple lines as one variable?

Post by jsmorley »

kyriakos876 wrote:I want the measure to update every, say 1 second, but stop if one condition is true. Stop. Like, not even check the other Condition in the same Skin Update. There is no other measure/meter triggering the Measure so setting UpdateDivider=-1 would simply make it update once.
No, all IfCondition / IfMatch options will be tested on each update of the measure. There is no "break" capability, as this is not a case / select / switch or if / then / else function. Each IfCondition(N) / IfTrueAction(N) / IfFalseAction(N) are in effect unrelated to other sets of tests and results. There is just no code block to break out of.

This means that you need to take some care with the order and range of how you test things, and what actions you take. If you ask "is #Var# > 10" and then ask "is #Var# > 0", when the value is "20", both are true, and in this case the action associated with the last one will be done last, and that may not be what you want.

If you want the full range of "if / then / elseif / else" or a loop with "break" capabilities, you are probably going to want to jump out to Lua for that. Rainmeter is NOT a procedural programming language, Lua is.
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: Multiple lines as one variable?

Post by fonpaolo »

kyriakos876 wrote:I want the measure to update every, say 1 second, but stop if one condition is true. Stop. Like, not even check the other Condition in the same Skin Update. There is no other measure/meter triggering the Measure so setting UpdateDivider=-1 would simply make it update once.
As jsmorley has pointed out, the IfConditions are tested on every skin update, so, my suggestion is to use them only when really needed.

The reason why I suggested to use UpdateDivider=-1 is simple: the plugin will retrieve the measure, if no other measures can be used to monitor changes, move the IfConditions in another measure and use UpdateDivider=-1, on the opposite, if there's another measure monitoring changes, add UpdateDivider=-1 to the measure with plugin and IfConditions and add to the first measure (the one monitoring) the OnChangeAction=!UpdateMeasure Measure withPluginandIfConditions.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Multiple lines as one variable?

Post by kyriakos876 »

jsmorley wrote:
This means that you need to take some care with the order and range of how you test things, and what actions you take. If you ask "is #Var# > 10" and then ask "is #Var# > 0", when the value is "20", both are true, and in this case the action associated with the last one will be done last, and that may not be what you want.
Yes! This is my case. :D Thanks for being straightforward.
jsmorley wrote: If you want the full range of "if / then / elseif / else" or a loop with "break" capabilities, you are probably going to want to jump out to Lua for that. Rainmeter is NOT a procedural programming language, Lua is.
That's what I thought... I just had to ask as I'll have to learn lua in order to do what I want. ^_^

Also what character should I add to IfMatch in order to make it match only if it matches exactly with the condition?
For example I have a string: "My car is blue and black"
If I write:

Code: Select all

IfMatch="My car is blue"
or

Code: Select all

IfMatch="blue"
or anything that has a word included, the condition will be true.
How do I make it match only if it is exactly "My car is blue"?

I am not familiar with regular expressions so yea.... (I read the IfMatchActions doc but I don't know what the characters .^$*+?()[{\| do. Would the following give the desired outcome?

IfMatch=(?=Blue)
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Multiple lines as one variable?

Post by kyriakos876 »

fonpaolo wrote:As jsmorley has pointed out, the IfConditions are tested on every skin update, so, my suggestion is to use them only when really needed.

The reason why I suggested to use UpdateDivider=-1 is simple: the plugin will retrieve the measure, if no other measures can be used to monitor changes, move the IfConditions in another measure and use UpdateDivider=-1, on the opposite, if there's another measure monitoring changes, add UpdateDivider=-1 to the measure with plugin and IfConditions and add to the first measure (the one monitoring) the OnChangeAction=!UpdateMeasure Measure withPluginandIfConditions.
Yeah...Well apparently I can't control the Inside-of-the-measure conditions one-by-one, which is what I was going for, but only as a whole. Thanks! :)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Multiple lines as one variable?

Post by jsmorley »

In that case, you want to indicate that the end of the string is reached when the match you are looking for is made. This is done with the $ character, which in the context of a regular expression means "end of string".

Code: Select all

[MeasureString]
Measure=String
String=My car is blue and black
IfMatch=(?i)my car is blue
IfMatchAction=[!Log "First match is true"]
IfNotMatchAction=[!Log "First match is false"]
IfMatch2=(?i)my car is blue$
IfMatchAction2=[!Log "Second match is true"]
IfNotMatchAction2=[!Log "Second match is false"]
So what I am doing in the first match is just looking for "my car is blue" in a case insensitive (?i) way. It will be true.
In the second match, I am looking for "my car is blue" and suggesting that that will also be the end of the string $. That will be false.

https://www.debuggex.com/cheatsheet/regex/pcre