It is currently March 29th, 2024, 8:32 am

Simple countdown timer

Get help with creating, editing & fixing problems with skins
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Simple countdown timer

Post by eclectic-tech »

sl23 wrote: July 22nd, 2021, 8:55 pm Ahh! I was literally putting the value in seconds rather than the formula.

Unfortunately this doesn't seem to work. :???:
Sorry, my quick reply will not work on that measure (it never changes value). :uhuh:

Without seeing all of your code, the MinValue/MaxValue must be set on a measure that calculates the remaining seconds from the current time to the target time; that measure would then be used in your bar meter.
You may need to create a new measure to calculate that value if one is not already in your skin.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Simple countdown timer

Post by eclectic-tech »

I took a closer look at TimerNixie and your code and found all you need to do is add the MinValue and MaxValue to [mLua] and bind that to your bar meter (I understood you want to replace the 'seconds' bar with the countdown bar).

So the changes to your code would look like this:

Code: Select all

...
[mLua]
Measure=Script
Group=Timers
ScriptFile=#CURRENTPATH#Timer.lua
IfCondition=mLua <= 0
IfTrueAction=#ActionToTake#
Disabled=1
MaxValue=((#TimerHours# * 3600) + (#TimerMinutes# * 60) + #TimerSeconds#)
MinValue=0

; [Second]
; Meter=Bar
; MeasureName=mSecond
; BarColor=235,170,0,255
; BarOrientation=Horizontal
; SolidColor=255,255,255,60
; X=r
; Y=12R
; W=150
; H=2

[TimerBar]
Meter=Bar
MeasureName=mLua
BarColor=235,170,0,255
BarOrientation=Horizontal
SolidColor=255,255,255,60
;Flip=1
X=r
Y=12R
W=150
H=2

...
shutdown20.png
Aside:
In working with your code I noticed a few issues.
You broke the countdown display by changing the section names the script expected to find and use to write updated time values; they must be named: [MeasureSeconds], [MeasureMinutes], and [MeasureHours].
Rather than hardcode the warning message times as variables, add those as seconds remaining (10 min = 600 seconds) and test them in a second 'IfCondition' in the [mLua] section.

Feel free to ignore these additional suggestions, it is your skin and it does work as you intended.
Here is your code with those suggestions:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
LeftMouseUpAction=[PlayStop]
RightMouseUpAction=[PlayStop]

[Bg]
Meter=Shape
Shape=Rectangle Rectangle 1,1,300+20,38,5 | StrokeWidth 1 | Extend StrokeAlpha | Fill Color 0,0,0,100
StrokeAlpha=Stroke Color 128,255,0,100
MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 0,255,255,255"][!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color 128,255,0,100"][!UpdateMeter *][!Redraw]
DynamicVariables=1
X=1

[Variables]
@Include=TimeSettings.inc
ActionToTake=[PlayLoop Alarm.wav][Shutdown=shutdown.exe -s -t 60 -f]

; Shutdown=shutdown.exe -s -t 60 -f
; HybridShutdown=shutdown.exe /s /hybrid /f /t 60
; Restart=shutdown.exe -r -t 0
; Hibernate=rundll32.exe powrprof.dll,SetSuspendState
; Lock=rundll32.exe user32.dll, LockWorkStation

Alarm=PlayLoop Alarm.wav
AlarmTime=8.05
OffTime=8.15

========================================
; Process
========================================
[mProcessTimerStart]
Measure=Calc
Formula=1
IfCondition=(mProcessRainmeter=1)
IfTrueAction=[!EnableMeasureGroup Timers][!UpdateMeasureGroup Timers][!Redraw]
IfFalseAction=[!DisableMeasureGroup Timers][!UpdateMeasureGroup Timers][!Redraw]

[mProcessRainmeter]
Measure=Plugin
Plugin=Process
ProcessName=Rainmeter.exe

========================================
; Timer Measures
========================================
[mNow]
Measure=Time
Group=Timers
UpdateDivider=-1
Disabled=1

[mTotalSeconds]
Measure=Calc
Group=Timers
Formula=(#TimerHours# * 3600) + (#TimerMinutes# * 60) + #TimerSeconds#
UpdateDivider=-1
Disabled=1

[mTarget]
Measure=Time
Group=Timers
Format=%#m/%#d/%Y %#H:%M:%S
TimeStamp=([mNow:TimeStamp] + [mTotalSeconds])
UpdateDivider=1
Disabled=1
DynamicVariables=1
OnUpdateAction=[!SetVariable Target "[mTarget]"][!UpdateMeasure mLua]

[mLua]
Measure=Script
Group=Timers
ScriptFile=#CURRENTPATH#Timer.lua
IfCondition=mLua <= 0
IfTrueAction=[!HideMeter Message1][!ShowMeter Message2][!Redraw][#ActionToTake#]
IfCondition2=(#CURRENTSECTION#=600)
IfTrueAction2=[!HideMeter Action][!ShowMeter Message1][#Alarm#][!Redraw]
Disabled=1
MaxValue=[&mTotalSeconds]
MinValue=0
DynamicVariables=1

[MeasureHours]
Measure=Calc
Formula=#TimerHours#
[MeasureMinutes]
Measure=Calc
Formula=#TimerMinutes#
[MeasureSeconds]
Measure=Calc
Formula=#TimerSeconds#

========================================
; TIME
========================================
[Style]
FontFace=Aller
AntiAlias=1
H=26

[mTime]
Measure=Time
Format=%#I.%M %p
Substitute=".":":"

[Time]
Meter=String
MeasureName=mTime
MeterStyle=Style
FontSize=24
FontColor=0,255,255
InlineSetting=Size | 15
InlinePattern=.*( .*)$
X=10
Y=-4

[TimerBar]
Meter=Bar
MeasureName=mLua
BarColor=235,170,0,255
BarOrientation=Horizontal
SolidColor=255,255,255,60
;Flip=1
X=r
Y=12R
W=150
H=2

[Action]
Meter=String
MeterStyle=Style
FontColor=235,170,100
FontSize=9
Text=Shutdown in:
X=180
Y=0
Hidden=0

[TimerDisplay]
Meter=String
MeasureName=MeasureSeconds
MeasureName2=MeasureMinutes
MeasureName3=MeasureHours
MeterStyle=Style
FontSize=15
FontColor=255,228,110,255
Text=%3h %2m %1s
X=r
Y=13

[Message1]
Meter=String
MeterStyle=Style
FontColor=255,128,0
Text=!! 10 Mins 'til Shutdown !!
Hidden=1
X=150
Y=0

[Message2]
Meter=String
MeterStyle=Style
FontColor=255,128,0
Text=!! Shutting down Now !!
Hidden=1
X=r
Y=0
You do not have the required permissions to view the files attached to this post.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Thank you for your help :thumbup: :thumbup: :thumbup:

I can see how your new code works, but I think you missed the point about requiring the OffTime Variable?
It's all good and works well so thanks again.

Btw, I'm not sure why you stated ...
eclectic-tech wrote: July 23rd, 2021, 1:23 am You broke the countdown display by changing the section names the script expected to find and use to write updated time values; they must be named: [MeasureSeconds], [MeasureMinutes], and [MeasureHours].
I changed these in the lua, so I don't understand how it's broken?

One other thing, how do I get the leading zeros shown in the countdown timer? So, instead of showing 2h 5m 5s it shows 2:05 05
I tried this, and some variations, but don't know what I should reference as the target meter?

Code: Select all


[mLua]
Measure=Script
ScriptFile=#CURRENTPATH#Timer.lua
IfCondition=mLua <= 0
IfTrueAction=[!SetOption TimerDisplay Text "#Message2##CRLF#%1:%2 %3"][!Redraw][#ActionToTake#]
IfCondition2=(#CURRENTSECTION#=600)
IfTrueAction2=[!SetOption TimerDisplay Text "#Message1##CRLF#%1:%2 %3"][#Alarm#][!Redraw]Disabled=1
IfCondition3=(#TimerHours# >= 0) && (#TimerHours# <= 9)
IfTrueAction3=[!SetOption mHours Prefix "0"]
IfFalseAction3=[!SetOption mHours Prefix ""]
IfCondition4=(#TimerMinutes# >= 0) && (#TimerMinutes# <= 9)
IfTrueAction4=[!SetOption #TimerMinutes# Prefix "0"]
IfFalseAction4=[!SetOption #TimerMinutes# Prefix ""]
IfCondition5=(#TimerSeconds# >= 0) && (#TimerSeconds# <= 9)
IfTrueAction5=[!SetOption #TimerSeconds# Prefix "0"]
IfFalseAction5=[!SetOption #TimerSeconds# Prefix ""]
MinValue=0
MaxValue=[&mTotalSeconds]
Group=Timers
DynamicVariables=1


[TimerDisplay]
Meter=String
MeasureName=mHours
MeasureName2=mMinutes
MeasureName3=mSeconds
MeterStyle=Style
FontSize=9
FontColor=255,228,110,255
InlineSetting=Size | 15 
InlinePattern=.+#CRLF#(.*) .*$
Text=#ActionText##CRLF#%1:%2 %3
X=200
Y=0

- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

How is this so difficult to achieve and why aren't the leading zeros there by default?

I've managed to get them shown but can't figure out why they still aren't working only on numbers under 10?

Here's some test code I've been working as an alternative approach within the same skin:

Code: Select all

========================================
; Alarm
========================================
[mDigitPrefixerAlarm]
Measure=calc
Formula=00
Dynamicvariables=1
IfCondition=(#TimerHours# >= 0) && (#TimerHours# <= 9) || (#TimerMinutes# >= 0) && (#TimerMinutes# <= 9) || (#TimerSeconds# >= 0) && (#TimerSeconds# <= 9)
IfTrueAction=[!SetOption HourAlarm Prefix "0"] || [!SetOption MinuteAlarm Prefix "0"] || [!SetOption SecondAlarm Prefix "0"]
IfFalseAction=[!SetOption HourAlarm Prefix ""] || [!SetOption MinuteAlarm Prefix ""] || [!SetOption SecondAlarm Prefix ""]
;IfCondition2=(#TimerMinutes# >= 0) && (#TimerMinutes# <= 9)
;IfTrueAction2=[!SetOption MinuteAlarm Prefix "0"]
;IfFalseAction2=[!SetOption MinuteAlarm Prefix ""]
;IfCondition3=(#TimerSeconds# >= 0) && (#TimerSeconds# <= 9)
;IfTrueAction3=[!SetOption SecondAlarm Prefix "0"]
;IfFalseAction3=[!SetOption SecondAlarm Prefix ""]
Group=Timers

[Alarm]
Measure=calc
Formula=0
DynamicVariables=1
IfCondition=(mHours = #TimerHours#) && (mMinutes = #TimerMinutes#) && (mSeconds = #TimerSeconds#)
IfTrueAction=[PlayLoop #Alarm#] [!Redraw]
Group=Timers

[HourAlarm]
Meter=String
MeasureName=mHours
MeterStyle=sAllText | sHighlight
Text=%1:
MouseScrollUpAction=[!SetVariable TimerHours (Clamp(#TimerHours#+1,0,23))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseScrollDownAction=[!SetVariable TimerHours (Clamp(#TimerHours#-1,0,23))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
X=29
Y=30

[MinuteAlarm]
Meter=String
MeasureName=mMinutes
MeterStyle=sAllText | sHighlight
Text=%1
MouseScrollUpAction=[!SetVariable TimerMinutes (Clamp(#TimerMinutes#+1,0,59))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseScrollDownAction=[!SetVariable TimerMinutes (Clamp(#TimerMinutes#-1,0,59))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
X=-2R
Y=r

[SecondAlarm]
Meter=String
MeasureName=mSeconds
MeterStyle=sAllText | sHighlight
Text=%1
MouseScrollUpAction=[!SetVariable TimerSeconds (Clamp(#TimerSeconds#+1,0,59))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseScrollDownAction=[!SetVariable TimerSeconds (Clamp(#TimerSeconds#-1,0,59))] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
X=4R
Y=r
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 11:37 am How is this so difficult to achieve and why aren't the leading zeros there by default?
Not difficult at all - in the eclectic-tech's code above just add:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*)$":"0\1","^.*(.{2})$":"\1"
to your [MeasureHours], [MeasureMinutes] and [MeasureSeconds] measures. If you want the same thing for the time on the left, just adjust the [mTime] measure's Format option accordingly, e.g. %H:%M:
CD.jpg
Note: What the substitute above does is add a 0 at the start of the string, irrespective of the number there, then keep the last 2 characters. For example, 9 -> 09 -> 09 and 21 -> 021 -> 21:
^ = start of string
$ = end of string
. = any character (with some exceptions, but they don't matter here)
* = any number of times for the preceding pattern (. in this case, so overall .* means any character any number of times)
() = the pattern between round brackets is "captured" (or "retained", if you like)
\1 = reference to capture number 1
{} = the pattern between curly brackets is a "quantifier", so the preceding pattern is taken {N} times
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Thanks, that's useful to know :thumbup:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 12:54 pm Thanks, that's useful to know :thumbup:

Sorry, but which bit of code do I add it to? I've tried several measures and nothing changes. :oops:
I already explained this above:
- take eclectic-tech code from the Spoiler here and paste it in your skin's .INI file, replacing its previous contents
- make the modifications I mentioned, where I mentioned
- save the .INI file
- refresh the skin
Is it clearer now? :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Sorry my mistake, I forgot to remove the code causing the issue! :oops:

Thanks again :thumbup:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Simple countdown timer

Post by Yincognito »

sl23 wrote: July 24th, 2021, 1:11 pm Sorry my mistake, I forgot to remove the code causing the issue! :oops:

Thanks again :thumbup:
Yeah, I kind of suspected that, that's why I added "replacing its previous contents" to my post afterwards.
Basically, so that you understand things better for the future, the order in which Rainmeter does things in a skin is more or less:
- measures ([sections] having Measure=... parts)
- [!bangs] in those measures, according to each measure and the options=... where those bangs belong
- meters ([sections] having Meter=... parts)
What you need to do when debugging something that has a visual expression in your skin is therefore, sort of backwards:
- identify the incriminated meter (quite obvious in this case, [TimerDisplay], judging by the contents or Text=... of the other meters)
- identify which measures are "linked" or "associated" with the said meter (by looking for MeasureNameN=... options)
- jump to those measures and see what's happening there and how stuff can be adjusted
In this specific case, since a measure has a number value and a string value, you had to modify the string value to match your preferences, naturally by manipulating that value through a substitution.

Most of this is easily noticeable when looking at the Skins Tab from the About window, where the number and the string value of every measure in your skin is shown. You can even make "step-by-step" substitutions, like only the Substitute="^(.*)$":"0\1" part, see the result after editing, saving and refreshing the skin, and then add the second part, i.e. ,"^.*(.{2})$":"\1" to the same Substitute option, in order to see exactly what's happening in each step of the way.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Thank you for explaining. That's really helpful.
The reason I'm struggling with this skin is more to do with the fact it uses lua rather than just Rainmeter code. I can just about work my way around a lot of issues when it's just Rainmeter code. But when lua and reg ex get involved, it throws me off as I don't know anything about either. That's why I originally looked for a straightforward Rainmeter based skin.
Thank you again.
- MuLab -