It is currently April 26th, 2024, 8:12 am

IfEqualValue / IfEqualAction help?

Get help with creating, editing & fixing problems with skins
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

IfEqualValue / IfEqualAction help?

Post by JayOtt »

Hey all,

So I have a skin that displays a service level and changes its colour from red, to yellow, to green depending on the number. If the number is 0, the colour should be white to indicate the value isn't being read.

Everything is working correctly, except the 0 value;

Code: Select all

[Rainmeter]
Author=Jay
Update=1000

[Variables]

TESTVALUE=0

WIDTH=150
HEIGHT=30
BGCOLOUR=15,15,15,150
TEXTCOLOR=255,255,255
FONTSIZE=12
WAITINGCOLOUR=255,255,255
AVAILCOLOUR=255,255,255
SVRLVLRED=255
SVRLVLGREEN=255
SVRLVLBLUE=0

[BG]
Meter=Image
SolidColor=#BGCOLOUR#
H=#HEIGHT#
W=#WIDTH#

[SrvLvlText]
StringStyle=BOLD
StringAlign=CENTER
FontColor=#SVRLVLRED#,#SVRLVLGREEN#,#SVRLVLBLUE#
FontSize=#FONTSIZE#
StringCase=Upper
AntiAlias=1
FontFace=Trebuchet MS
Y=r

;-------------------------

[MeasureSrvLvl]
Measure=Calc
Formula=#TESTVALUE#

[MeasureSrvLvlRed]
Measure=Calc
Formula=MeasureSrvLvl
DynamicVariables=1
IfEqualValue=0
IfEqualAction=[!RainmeterSetVariable SVRLVLRED 255]
IfAboveValue=79
IfAboveAction=[!RainmeterSetVariable SVRLVLRED 0]
IfBelowValue=80
IfBelowAction=[!RainmeterSetVariable SVRLVLRED 255]

[MeasureSrvLvlGreen]
Measure=Calc
Formula=MeasureSrvLvl
DynamicVariables=1
IfEqualValue=0
IfEqualAction=[!RainmeterSetVariable SVRLVLGREEN 255]
IfAboveValue=69
IfAboveAction=[!RainmeterSetVariable SVRLVLGREEN 255]
IfBelowValue=70
IfBelowAction=[!RainmeterSetVariable SVRLVLGREEN 0]

[MeasureSrvLvlBlue]
Measure=Calc
Formula=MeasureSrvLvl
DynamicVariables=1
IfAboveValue=0
IfAboveAction=[!RainmeterSetVariable SVRLVLBLUE 0]
IfBelowValue=1
IfBelowAction=[!RainmeterSetVariable SVRLVLBLUE 255]

;-------------------------

[MeterSrvLvl]
DynamicVariables=1
MeterStyle=SrvLvlText
MeasureName=MeasureSrvLvl
Meter=STRING
X=75
Y=5
Prefix="Srv Lvl: "
Postfix="%"

;-------------------------
Green isn't being set to 255 when the service level is 0. As far as I can see it's exactly the same code as red, which appears to work properly.

Any ideas?
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfEqualValue / IfEqualAction help?

Post by balala »

A much better solution would be to use IfConditions instead of IfActions. IfActions are old and have their own limits, IfConditions are much more reliable.
For example replace the [MeasureSrvLvlRed], [MeasureSrvLvlGreen] and [MeasureSrvLvlBlue] measures with the following ones:

Code: Select all

[MeasureSrvLvlRed]
Measure=Calc
Formula=MeasureSrvLvl
IfCondition=(#CURRENTSECTION#<80)
IfTrueAction=[!SetVariable SVRLVLRED "255"]
IfFalseAction=[!SetVariable SVRLVLRED "0"]
;DynamicVariables=1
;IfEqualValue=0
;IfEqualAction=[!RainmeterSetVariable SVRLVLRED 255]
;IfAboveValue=79
;IfAboveAction=[!RainmeterSetVariable SVRLVLRED 0]
;IfBelowValue=80
;IfBelowAction=[!RainmeterSetVariable SVRLVLRED 255]

[MeasureSrvLvlGreen]
Measure=Calc
Formula=MeasureSrvLvl
IfCondition=((#CURRENTSECTION#=0)||(#CURRENTSECTION#>=70))
IfTrueAction=[!SetVariable SVRLVLRED "255"]
IfFalseAction=[!SetVariable SVRLVLRED "0"]
;DynamicVariables=1
;IfEqualValue=0
;IfEqualAction=[!RainmeterSetVariable SVRLVLRED 255]
;IfAboveValue=69
;IfAboveAction=[!RainmeterSetVariable SVRLVLRED 255]
;IfBelowValue=70
;IfBelowAction=[!RainmeterSetVariable SVRLVLRED 0]

[MeasureSrvLvlBlue]
Measure=Calc
Formula=MeasureSrvLvl
IfCondition=(#CURRENTSECTION#>0)
IfTrueAction=[!SetVariable SVRLVLblue "0"]
IfFalseAction=[!SetVariable SVRLVLblue "255"]
;DynamicVariables=1
;IfAboveValue=0
;IfAboveAction=[!RainmeterSetVariable SVRLVLBLUE 0]
;IfBelowValue=1
;IfBelowAction=[!RainmeterSetVariable SVRLVLBLUE 255]
See that I commented out the old conditions, just to can easily check the new ones. I also commented out the DynamicVariables=1 option, because it's not needed and as such, doesn't worth to use it.

Additional tip: !Rainmeter... is a deprecated bang prefix, don't use it.
User avatar
JayOtt
Posts: 14
Joined: February 19th, 2019, 2:15 pm

Re: IfEqualValue / IfEqualAction help?

Post by JayOtt »

Beautiful! I wasn't aware of IfCondition! Works perfectly, thank you. :D
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: IfEqualValue / IfEqualAction help?

Post by balala »

JayOtt wrote: March 13th, 2019, 1:19 pm Beautiful! I wasn't aware of IfCondition! Works perfectly, thank you. :D
Since IfCondition is a newer option than IfActions and it also has a lot of advantages (like the possibility to set any number of conditions, not just three like IfBelow, IfEqual and IfAbove), it's always better to be used.
I'm glad if you got it working well.