It is currently April 27th, 2024, 3:47 am

Help with IF statements

Get help with installing and using Rainmeter.
riciuxas
Posts: 2
Joined: October 2nd, 2015, 9:22 am

Help with IF statements

Post by riciuxas »

I'm trying to take measure of time, then have one second further and one second back - so in total it should display 3 clocks. When the current clock reaches 59, the future clock should show 00 instead of 60. Problem is, it drops to 0 and never moves again. I think it just never resets the statement value, but I have no idea where should I go from there. Code:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,0


[MeasureMin1]
Measure=Time
Format=%#M

[MeasureSec1]
Measure=Time
Format=%#S

[MeasureHrs1]
Measure=Time
Format=%H

[MeasureMin2]
Measure=Calc
Formula=MeasureA+3

[MeasureSec-]
Measure=Calc
Formula=MeasureSec1-1

[MeasureSec+]
Measure=Calc
Formula=MeasureSec1+1
IfAboveValue=58
IfAboveAction=[!SetOption MeasureSec+ Formula 00][!Redraw]
IfBelowValue=59
IfBelowValue=[!SetOption MeasureSec+ Formula MeasureSec1+1][!Redraw]



[MeterText1]
Meter=String
MeasureName=MeasureHrs1
MeasureName2=MeasureMin1
MeasureName3=MeasureSec-

X=20
Y=5
W=200
H=50
FontFace=Adobe Gothic Std B
FontColor=255,255,255,127
FontSize=25
AntiAlias=1
Text="%1:%2:%3"

[MeterText2]
Meter=String
MeasureName=MeasureHrs1
MeasureName2=MeasureMin1
MeasureName3=MeasureSec1

X=5
Y=45
W=200
H=50
FontFace=Adobe Gothic Std B
FontColor=255,255,255,255
FontSize=25
AntiAlias=1
Text="%1:%2:%3"

[MeterText3]
Meter=String
MeasureName=MeasureHrs1
MeasureName2=MeasureMin1
MeasureName3=MeasureSec+

X=20
Y=85
W=200
H=50
FontFace=Adobe Gothic Std B
FontColor=255,255,255,127
FontSize=25
AntiAlias=1
Text="%1:%2:%3"
User avatar
NighthawkSLO
Posts: 21
Joined: October 22nd, 2014, 7:11 pm

Re: Help with IF statements

Post by NighthawkSLO »

It seems like you would want the clock to show +1 sec in time, right? In your example, even if it worked, it would show:
  • Past: 23:59:58
    Now: 23:59:58
    Future: 23:59:00
you can use timestamps to make it correct:

Code: Select all

[MeasureNow]
Measure=Time
;default format is %H:%M:%S so it's fine

[Measure-1s]
Measure=Time
Timestamp=([MeasureNow:Timestamp]-1)
DynamicVariables=1

[Measure+1s]
Measure=Time
Timestamp=([MeasureNow:Timestamp]+1)
DynamicVariables=1
riciuxas
Posts: 2
Joined: October 2nd, 2015, 9:22 am

Re: Help with IF statements

Post by riciuxas »

Well, it is working as intended, almost, it shows:

11:31:57
11:31:58
11:31:59

problem occurs when it reaches 58-59-60/00, because I don't know how to skip a number. I'll try it your way and report how it goes!

EDIT: SUPER! Thank you for the help! Can you tell me what was wrong with those IFs?
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with IF statements

Post by balala »

Altough NighthawkSLO's solution with timpstamp is the best, you can also make it without the TimeStamp option. For that, in your initial code, you have to:
1. Remove the IfAboveValue, IfAboveAction, IfBelowValue and IfBelowValue options from the [MeasureSec+] measure. You don't need them. Instead modify the Formula of this measure to: Formula=(( MeasureSec1 + 1 ) % 60 ). With the original formula you'll have troubles when the number of seconds is 59: in this moment the (MeasureSec1+1) formula returns 60, while =(( MeasureSec1 + 1 ) % 60 ) returns 0 (% is the remainder of the division).
2. Also modify the Formula of the [MeasureSec-] measure to: Formula=((( MeasureSec1 - 1 ) < 0 ) ? 59 : ( MeasureSec1 - 1 )).
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with IF statements

Post by balala »

And two more things: first, you can add the leading zeros to the seconds and minutes. To do that, remove the #, from the [MeasureMin1] and [MeasureSec1] measures and add the following options to the [MeasureSec-] and [MeasureSec+] measures:

Code: Select all

RegExpSubstitute=1
Substitute="^(\d{1})$":"0\1"
Second, the [MeasureMin2] measure is useless, you can remove it (at least if you don't have unposted sections).