It is currently October 19th, 2020, 9:24 pm

Need help with using measures as an if-then condition

Help with creating, editing & fixing problems with skins
EnhancedJax
Posts: 2
Joined: October 17th, 2020, 11:57 am

Need help with using measures as an if-then condition

Post by EnhancedJax »

For my skin, I wanted it so when I use a bang, it will trigger the measure, which tests what the #page# variable is with IfCondition and execute different actions then. I've tried many things but it didn't seem to work as I would like it to.

My Code:
called with:

Code: Select all

[!UpdateMeasure PageMeasure]
Measure:

Code: Select all

[PageMeasure]
Measure=Calc
Formula=#Page#
IfCondition=(#Page#=1)
IfTrueAction=[!SetOption "MyMeter" "MyMeterOption" "MyMeterOptionValue"]
regards,
Jax
User avatar
jsmorley
Developer
Posts: 21421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help with using measures as an if-then condition

Post by jsmorley »

EnhancedJax wrote: October 17th, 2020, 12:05 pm For my skin, I wanted it so when I use a bang, it will trigger the measure, which tests what the #page# variable is with IfCondition and execute different actions then. I've tried many things but it didn't seem to work as I would like it to.

My Code:
called with:

Code: Select all

[!UpdateMeasure PageMeasure]
Measure:

Code: Select all

[PageMeasure]
Measure=Calc
Formula=#Page#
IfCondition=(#Page#=1)
IfTrueAction=[!SetOption "MyMeter" "MyMeterOption" "MyMeterOptionValue"]
regards,
Jax

Try adding DynamicVariables=1 to the [PageMeasure] measure.
EnhancedJax
Posts: 2
Joined: October 17th, 2020, 11:57 am

Re: Need help with using measures as an if-then condition

Post by EnhancedJax »

Alright, seem to always forgot to add that to my meters, thanks for pointing out! It's working perfectly, but will it action per update or just when I update the measure? If so how can I make it not?
User avatar
Yincognito
Posts: 2760
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Need help with using measures as an if-then condition

Post by Yincognito »

EnhancedJax wrote: October 17th, 2020, 1:22 pmAlright, seem to always forgot to add that to my meters, thanks for pointing out!
Actually, it's quite easy to remember: if you think the value of a variable (which can be a measure/meter itself, for example a section variable) you use in a measure/meter changes while the skin is active, then add DynamicVariables=1 to the said measure/meter; if you don't, then it'll work fine without that line.
EnhancedJax wrote: October 17th, 2020, 1:22 pmIt's working perfectly, but will it action per update or just when I update the measure? If so how can I make it not?
A skin update (i.e. the one based on the Update value in the [Rainmeter] section of a skin) will usually trigger the update of all its elements, so in most cases, "per update" and "on measure update" are the same thing. Of course, given the fact that you can have different UpdateDividers for the skin elements or even have Disabled measures, this won't always be true, but these are just exceptions from the rule.

That being said, the answer is that it will action when the measure is updated, and this is easy to see if you update the measure on demand (like you just did in your code). There is a subtle difference though in these cases, and that is whether it will action each time the logical result of the condition changes or whether it will action each time the measure is updated, irrespective of the change in the logical result of the condition. To make that behavior clear, the IfConditionMode option exists. Setting this to 1 offers an alternative to the default behavior of the IfCondition, i.e.
the action is executed only once when the condition becomes "true", so it needs to become "false" and again "true" to execute again
by changing it so:
the evaluation of the condition will execute the appropriate actions in IfTrueAction or IfFalseAction on every update of the measure
basically relating to what I said earlier about the subtle difference in behavior based on the change in the logical result of the condition.

If by any chance you want to sometimes run the actions in the IfConditions and sometimes avoid running them, the easiest way to do it is to add an additional test, based on some corresponding value, e.g. IfCondition=(#Page#=1) && (#RunActions#=1) (&& stands for logical AND, while || stands for logical OR), where RunActions would be a variable that is 0 when you want to avoid it and 1 when you want to do it. Bear in mind though that this will change the logical result of the test I talked about earlier, especially if you don't use IfConditionMode, so you may need to tweak how you update or test conditions in the measure, in order to achieve the expected behavior.
User avatar
balala
Rainmeter Sage
Posts: 11575
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need help with using measures as an if-then condition

Post by balala »

EnhancedJax wrote: October 17th, 2020, 1:22 pm but will it action per update or just when I update the measure? If so how can I make it not?
Maybe I'm misunderstanding your question, but take in account the followings: as Yincognito said, the IfTrueAction is executed only once, when the condition stated into the IfCondition option becomes true. For a new execution, the condition has to turn to false, then to true again. The IfConditionMode=1 (IfMatchAction=1) option can avoid this, if it's added to the measure, the IfTrueAction will be executed on each update of the measure, while the condition is true.
On the other hand, if you want to execute the IfTrueAction only on demand, add an UpdateDivider=-1 option to the measure. Just take care that such in a case, the measure is updated only when you're updating either the measure (with a !UpdateMeasure / !UpdateMeasureGroup bang), or the skin itself (with !Update) and accordingly the IfTrueAction is executed only on update (done as described above), if IfCondition turns out to be true.
User avatar
Yincognito
Posts: 2760
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Need help with using measures as an if-then condition

Post by Yincognito »

balala wrote: October 17th, 2020, 6:03 pm[...] IfMatchAction=1 option can avoid this [...]
You probably meant IfConditionMode, since the OP test is numerical, in this case. ;-)
User avatar
balala
Rainmeter Sage
Posts: 11575
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need help with using measures as an if-then condition

Post by balala »

Yincognito wrote: October 17th, 2020, 6:10 pm You probably meant IfConditionMode, since the OP test is numerical, in this case. ;-)
Right. My usual inatention. :oops: Sorry, fixing my above reply...
User avatar
Yincognito
Posts: 2760
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Need help with using measures as an if-then condition

Post by Yincognito »

balala wrote: October 17th, 2020, 6:15 pm Right. My usual inatention. :oops: Sorry, fixing my above reply...
Yep, I was actually going to add that you don't have to say "sorry" on this one to the above post. Too late, it seems... :D
User avatar
balala
Rainmeter Sage
Posts: 11575
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need help with using measures as an if-then condition

Post by balala »

Yincognito wrote: October 17th, 2020, 6:23 pm Yep, I was actually going to add that you don't have to say "sorry" on this one to the above post. Too late, it seems... :D
On such a trivial mistake I have to add it for sure.
User avatar
Yincognito
Posts: 2760
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Need help with using measures as an if-then condition

Post by Yincognito »

balala wrote: October 17th, 2020, 6:46 pm On such a trivial mistake I have to add it for sure.
And I probably shouldn't have mentioned such a trivial mistake. Oops, my time to say sorry... :oops: