It is currently September 8th, 2024, 12:00 am

Losing values after restart, how do I solve that the best way?

Get help with creating, editing & fixing problems with skins
User avatar
HLHM
Posts: 9
Joined: August 13th, 2023, 2:07 pm

Losing values after restart, how do I solve that the best way?

Post by HLHM »

Hello.

I'm going gray soon...

I have made a small piece that calculates the time between a start time and the present time.

This works (it's probably not the best solution, but it works).

My problem occurs when the skin restarts. Then I lose correct value in "mStartingTime1".

I want to be able to save the value in "mStartingTime1" to a file that is loaded on startup to a variable. This variable replaces Measure.
Am I thinking crazy?
How should I attack this problem for me?
Grateful for any help.

\HLM
(Translated with Google translate from Swedish)

Code: Select all

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

[Metadata]
Name=Resist the urge to smoke
Author=HLMGBG
Version=1.0

[Variables]
hImg1=#@#Cig.png

[MeterMainBOXborder]
Meter=Image
SolidColor=222,222,222
X=0
Y=0
W=260
H=200

[MeterVer]
Meter=String
Y=2
X=2
Text=1.0

[MeterTitel]
Meter=STRING
StringAlign=CENTER
FontColor=140,140,150
FontFace=Courier New
FontSize=13
FontWeight=700
AntiAlias=1
Y=5
X=130
W=115
H=18
Text="Elapsed time since:"

;///////////////////// MEASURES //////////////////
[mSkinStarted]
Measure=Time
Format=%F %X
UpdateDivider=-1

[mTimeNow]
Measure=Time

[mFullTimeNow]
Measure=Time
Format=%F %X

[mStartingTime1]
Measure=Time
UpdateDivider=-1

[mStartingTime1b]
Measure=Time
Format=%F %X
UpdateDivider=-1

[mDiff1]
Measure=Time
TimeStamp=([mTimeNow:]-[mStartingTime1:])
DynamicVariables=1
UpdateDivider=1

[mDiffHours1]
Measure=Time
TimeStamp=([mTimeNow:]-[mStartingTime1:])
DynamicVariables=1
Format=%H
UpdateDivider=1

[mDiffMinutes1]
Measure=Time
TimeStamp=([mTimeNow:]-[mStartingTime1:])
DynamicVariables=1
Format=%M
UpdateDivider=1

[mDays1]
Measure=Uptime
Format=%4!i! d 
SecondsValue=([mTimeNow:TimeStamp]-[mStartingTime1:TimeStamp])
DynamicVariables=1

;//////////////////////  METERS ////////////////
[MeterImg1]
Meter=Image
ImageName=#hImg1#
ToolTipType=0
ToolTipText=Press here when you take a smoke
Y=30
X=5
W=50
H=50
LeftMouseUpAction=[!UpdateMeasure mStartingTime1] [!UpdateMeasure mStartingTime1b]


;------  temp -------
[MeterDiff]
Meter=String
MeasureName=mDiff1
SolidColor=255,255,255
FontFace=Courier New
StringAlign=Right
Y=90
X=255
W=250
Text=Elapsed: %1
;---------- \temp ----------

[MeterDiffFull1]
Meter=String
MeasureName=mDays1
MeasureName2=mDiffHours1
MeasureName3=mDiffMinutes1
SolidColor=255,255,255
FontFace=Courier New
StringAlign=Right
Y=50
X=255
W=180
Text=%1ays %2 hours %3 min

[MeterLastChange1]
Meter=String
MeasureName=mStartingTime1b
SolidColor=255,255,255
FontFace=Courier New
StringAlign=Right
Y=110
X=255
W=250
Text=LastChange: %1

[MeterTime Now1]
Meter=String
MeasureName=mFullTimeNow
SolidColor=255,255,255
FontFace=Courier New
StringAlign=Right
Y=130
X=255
W=250
Text=Time Now: %1

[MeterSkinStart]
Meter=String
MeasureName=mSkinStarted
SolidColor=255,255,255
FontFace=Courier New
StringAlign=Right
Y=150
X=255
W=250
Text=Skin Start: %1

You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Losing values after restart, how do I solve that the best way?

Post by Yincognito »

HLHM wrote: July 6th, 2024, 2:56 am I want to be able to save the value in "mStartingTime1" to a file that is loaded on startup to a variable. This variable replaces Measure.
Am I thinking crazy?
How should I attack this problem for me?
This is possible.

To load a variable from a file on skin load, see:
https://docs.rainmeter.net/manual/skins/include-option/
To save the value of a variable to that file, see:
https://docs.rainmeter.net/manual/bangs/#WriteKeyValue
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
HLHM
Posts: 9
Joined: August 13th, 2023, 2:07 pm

Re: Losing values after restart, how do I solve that the best way?

Post by HLHM »

Yincognito wrote: July 6th, 2024, 10:14 am This is possible.

To load a variable from a file on skin load, see:
https://docs.rainmeter.net/manual/skins/include-option/
To save the value of a variable to that file, see:
https://docs.rainmeter.net/manual/bangs/#WriteKeyValue
Thank you for the pointed direction to these methods.
It worked like a charm with this. :thumbup:

Code: Select all

[Variables]
vStartingTime1=13364941886
...

...
LeftMouseUpAction=[!WriteKeyValue "Variables" "vStartingTime1" [mTimeNowCalc]] [!Refresh]
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Losing values after restart, how do I solve that the best way?

Post by Yincognito »

HLHM wrote: July 8th, 2024, 10:23 pm Thank you for the pointed direction to these methods.
It worked like a charm with this. :thumbup:

Code: Select all

[Variables]
vStartingTime1=13364941886
...

...
LeftMouseUpAction=[!WriteKeyValue "Variables" "vStartingTime1" [mTimeNowCalc]] [!Refresh]
You're welcome, glad to help. Refreshing at the end is not absolutely necessary if your variable already has the same value in memory, via either assignment in [Variables] (like here) or !SetVariable, update related measures / meters and redraw (if previously the variable didn't yet have that value). ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth