It is currently July 16th, 2024, 1:41 pm

## IfConditions

Changes made during the Rainmeter 3.1 beta cycle.
Brian
Developer
Posts: 2706
Joined: November 24th, 2011, 1:42 am
Location: Utah

### IfConditions

We have added a new IfAction option called IfConditions.

IfConditions allow you to evaluate a mathematical formula that will execute an action based on when the formula is either true or false. IfConditions can be used in any type of measure and you may have multiple IfConditions per measure (eg. IfCondition2/IfTrueAction2/IfFalseAction2). Formulas need to follow the same rules as the Formula option for Calc measures. All the mathematical operators, constants, and functions (except Random and Counter) are available to use. Like Calc, measure names do not need [brackets] and are always dynamic when referenced inside the condition.

Options:
• IfCondition - A mathematical formula that will evaluate to either true or false.
• IfTrueAction - If the condition is true, this action is executed only once when the condition becomes "true", so it needs to become "false" and again "true" to execute again.
• IfFalseAction - If the condition is false, this action is executed only once when the condition becomes "false", so it needs to become "true" and again "false" to execute again.
• IfConditionMode - If set to 1, the appropriate actions will execute on every update of the measure instead of the default behavior (described above).

Here's how it works:
1. Define a boolean condition, which is a formula that evaluates to true or false.
Example: IfCondition=(MeasureCPU >= 10) && (MeasureCPU < 90)
2. Define a True and/or False action to perform when the IfCondition is evaluated.
Example: IfTrueAction=[!SetOption MeterCPU Text "CPU usage is between 10 and 90 percent!"]
Note: The comparison on either side of logical AND && and OR || operators must be enclosed in (parentheses).

That's it!

Here are some example skins made by jsmorley. They are all included in the .rmskin:
IfCondition_1.0.rmskin
IfCondition.jpg
Counter
Dice
OddEven
SameDifferent
Weekday
-Brian
You do not have the required permissions to view the files attached to this post.
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

### Re: IfConditions

very nice addition! and probably easier to understand than the IfAboveValue, IfBelowValue conditions.

now give me:

Code: Select all

``````IfConditionRegExp="(?si)^.*(rain).*\$"
IfMatchAction=...
IfNoMatchAction=...``````
to execute something when the weather is Rain, Heavy Rain, Rainshowers, etc. for example
jsmorley
Developer
Posts: 22646
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

### Re: IfConditions

moshi wrote:very nice addition! and probably easier to understand than the IfAboveValue, IfBelowValue conditions.

now give me:

Code: Select all

``````IfConditionRegExp="(?si)^.*(rain).*\$"
IfMatchAction=...
IfNoMatchAction=...``````
to execute something when the weather is Rain, Heavy Rain, Rainshowers, etc. for example
You are like a bad, spoiled child!

I would think that you could use RegExpSubtitute on the WebParser measure to turn the "weather condition" into a number with that regular expression. Then use as many IfConditionN as you need to take actions based on the "true" or "false" tests.

Sort of "anything with rain is 1", "anything with cloudy is 2", "anything with thunder is 3", etc...

Not that some kind of regular expression based IfCondition wouldn't be nice, but it is a different animal to create than the one that is based on the existing math "conditional formula" functionality we use. We didn't really have to invent any wheels to get this. We basically just add "? 1 : 0" to the end of the formula in IfCondition, and off it goes.
jsmorley
Developer
Posts: 22646
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

### Re: IfConditions

P.S. Moshi, this can in fact pretty much replace the IFAction functionality, while being arguably easier to understand and certainly much more powerful.

Same thing done with IFActions and IFConditions:

Code: Select all

``````[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureIfActionTime]
Measure=Time
Format=%#S
IfAboveValue=29
IfAboveAction=[!SetOption MeterIfAction SolidColor "76,179,54,255"]
IfBelowValue=30
IfBelowAction=[!SetOption MeterIfAction SolidColor "54,124,179,255"]

[MeasureIfConditionTime]
Measure=Time
Format=%#S
IfCondition=MeasureIfConditionTime >= 30
IfTrueAction=[!SetOption MeterCondition SolidColor "76,179,54,255"]
IfFalseAction=[!SetOption MeterCondition SolidColor "54,124,179,255"]

[MeterIfAction]
Meter=String
MeasureName=MeasureIfActionTime
FontSize=14
FontColor=226,252,220,255
StringStyle=Bold
AntiAlias=1

[MeterCondition]
Meter=String
MeasureName=MeasureIfConditionTime
X=5R
FontSize=14
FontColor=226,252,220,255
StringStyle=Bold
AntiAlias=1
``````
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

### Re: IfConditions

jsmorley wrote:I would think that you could use RegExpSubtitute on the WebParser measure to turn the "weather condition" into a number with that regular expression. Then use as many IfConditionN as you need to take actions based on the "true" or "false" tests.
yeah, pretty much everything is possible with RegExpSubstitute, i just would love to add this to the tips & tricks section:

Code: Select all

``````Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_NAME
IfConditionRegExp="^(Rogers1967)\$"
IfMatchAction=[PLAYLOOP beep.wav]``````
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

### Re: IfConditions

Code: Select all

``````Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_NAME
IfConditionRegExp="^(Rogers1967)\$"
IfMatchAction=[PLAYLOOP beep.wav]``````
xD
Rainmeter - You are only limited by your imagination and creativity.
amc242
Posts: 25
Joined: July 12th, 2012, 2:02 pm

### Re: IfConditions

Code: Select all

``````Measure=Plugin
Plugin=SysInfo
SysInfoType=USER_NAME
IfConditionRegExp="^(Rogers1967)\$"
IfMatchAction=[PLAYLOOP beep.wav]``````
This won't work. His username is "Rogers", and that could hurt millions of innocent Rogers.
But his PC name is "Rogers-PC"...
MikeG621
Posts: 87
Joined: March 18th, 2013, 1:59 pm

### Re: IfConditions

Excellent, I've been wanting this functionality for a while because the current methods are quite tedious.