It is currently May 7th, 2024, 3:34 am

Hide/Show Meters

Get help with creating, editing & fixing problems with skins
NewWave
Posts: 23
Joined: April 15th, 2012, 5:39 am

Hide/Show Meters

Post by NewWave »

Could someone kindly tell me why the following doesn't work. I want it to display "AM" or "PM" during the appropriate time of day.

Code: Select all

[Rainmeter]
Update=1000

[MeasureAMPM]
Measure=Time
Format=%p
Substitute="AM":"0","PM":"1"
IfBelowValue=1
IfBelowAction=!Execute [!ShowMeter MeterAM] [!HideMeter MeterPM]
IfAboveValue=0
IfAboveAction=!Execute [!HideMeter MeterAM] [!ShowMeter MeterPM]

[MeterTEST]
Meter=String
MeasureName=MeasureAMPM
X=0
Y=0
FontSize=12
FontColor=255,255,255
Text=MeasureAMPM returns %1

[MeterAM]
Meter=String
X=0
Y=20
Hidden=1
FontSize=12
FontColor=255,255,255
Text=AM

[MeterPM]
Meter=String
X=0
Y=20
Hidden=1
FontSize=12
FontColor=255,255,255
Text=PM
Thanks for any help.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Hide/Show Meters

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureAMPM]
Measure=Time
Format=%p
Substitute="AM":"0","PM":"1"

[MeasureCalcAMPM]
Measure=Calc
Formula=[MeasureAMPM]
IfBelowValue=1
IfBelowAction=!Execute [!ShowMeter MeterAM][!HideMeter MeterPM]
IfEqualValue=1
IfEqualAction=!Execute [!HideMeter MeterAM][!ShowMeter MeterPM]
DynamicVariables=1

[MeterTEST]
Meter=String
MeasureName=MeasureAMPM
X=0
Y=0
FontSize=12
FontColor=255,255,255
Text=MeasureAMPM returns %1

[MeterAM]
Meter=String
X=0
Y=20
Hidden=1
FontSize=12
FontColor=255,255,255
Text=AM

[MeterPM]
Meter=String
X=0
Y=20
Hidden=1
FontSize=12
FontColor=255,255,255
Text=PM
The problem is that the Time measure is returning a string "AM / PM". You are welcome to do a Substitute on the value to change it to a number, but any IfAction on the same measure will use the original return value, not the substituted value. Since both "AM" and "PM" resolve to zero when treated as a number, that is all the IfAction will ever see. "The sun never sets on the British Empire"...

So we create a secondary Calc measure, which, since we put DynamicVariables=1 on it and use the value of the Time measure in brackets, uses the substituted value. Now we are getting "0" or "1" properly, and the show/hide bangs work.

By the way, you can simplify this a bit:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureAMPM]
Measure=Time
Format=%p
Substitute="AM":"0","PM":"1"

[MeasureCalcAMPM]
Measure=Calc
Formula=[MeasureAMPM]
IfBelowValue=1
IfBelowAction=!SetOption MeterAMPM Text "AM"
IfEqualValue=1
IfEqualAction=!SetOption MeterAMPM Text "PM"
DynamicVariables=1

[MeterTEST]
Meter=String
MeasureName=MeasureAMPM
X=0
Y=0
FontSize=12
FontColor=255,255,255
Text=MeasureAMPM returns %1

[MeterAMPM]
Meter=String
X=0
Y=20
FontSize=12
FontColor=255,255,255
Or even simpler:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureAMPM]
Measure=Time
Format=%p

[MeterTEST]
Meter=String
MeasureName=MeasureAMPM
X=0
Y=0
FontSize=12
FontColor=255,255,255
Text=MeasureAMPM returns %1

[MeterAMPM]
Meter=String
X=0
Y=20
FontSize=12
FontColor=255,255,255
Text=[MeasureAMPM]
DynamicVariables=1
NewWave
Posts: 23
Joined: April 15th, 2012, 5:39 am

Re: Hide/Show Meters

Post by NewWave »

I understand. Thanks for such an informative, thorough answer. I appreciate it.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Hide/Show Meters

Post by jsmorley »

My pleasure.