It is currently July 17th, 2019, 1:46 pm

Using Counter for Skin "OnLoadAction"

Tips and Tricks from the Rainmeter Community
User avatar
jsmorley
Developer
Posts: 19287
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Using Counter for Skin "OnLoadAction"

jsmorley » January 30th, 2016, 3:42 pm

Overview: The Counter Function

One of the built-in functions in a Calc measure in Rainmeter is the "Counter" function.

https://docs.rainmeter.net/manual/measures/calc/#Functions

What this is, as the name implies, is a "counter" that is associated with a skin. It begins counting when the skin is loaded, and increments on every skin "update".

The benefit of this counter, what makes it different from:

Code: Select all

[MeasureCount]
Measure=Calc
Formula=MeasureCount + 1
is that it is not reset when the skin is refreshed.

So if you were for instance doing some animation using:

Code: Select all

[MeasureAnimation]
Measure=Calc
Formula=(MeasureAnimation % 10) + 1
That measure would be reset to "1" and start over on a skin refresh. That may be what you want, but

Code: Select all

[MeasureAnimation]
Measure=Calc
Formula=Counter %10
Will work the same, except that on a skin refresh, the animation would just carry on where it left off, and not start over.

Using Counter to return the Load Status of a Skin

So with that overview in mind, let's turn to the subject of this "Tips % Tricks".

Something you might like to test for in a skin is an indication that the skin was "just loaded" or "just refreshed". While you can use OnRefreshAction in the [Rainmeter] section of the skin to take some action when a skin is refreshed, that function actually treats "just refreshed" and "just loaded" as exactly the same thing. It will be fired on either. However there may be cases where you want to distinctly know if the skin was "just loaded", and not "just refreshed". There is no built-in OnLoadAction in Rainmeter, nor, for some backwards-compatibility reasons, can there be.

You might want the loading of a skin to load or unload some other skins, run some animation just one time, or some other action you want distinctly triggered by a skin being "loaded", but not "refreshed".

Easiest way to explain this is with a skin:

Code: Select all

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

[MeasureReportTime]
Measure=Time
Format=%A, %B %#d, %Y at %#I:%M:%S %p
UpdateDivider=-1

[MeasureLoadStatus]
Measure=Calc
Formula=Counter
IfCondition=MeasureLoadStatus = 1
IfTrueAction=[!UpdateMeasure MeasureReportTime][!SetOption MeterLoadStatus Text "Skin Loaded#CRLF#[MeasureReportTime]"]
IfCondition2=MeasureLoadStatus > 1
IfTrueAction2=[!UpdateMeasure MeasureReportTime][!SetOption MeterLoadStatus Text "Skin Refreshed#CRLF#[MeasureReportTime]"]
UpdateDivider=-1

[MeterLoadStatus]
Meter=String
FontSize=12
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
The meat-and-potatoes of this is the [MeasureLoadStatus] Calc measure. What it does is simply use the Counter function as the formula.

If Counter is "1", then we know the skin was just loaded. We can take whatever action we want based on that. Counter will never be "1" again, unless you unload and reload the skin. A refresh will not reset Counter.

If Counter is ">1" then we know the skin was just refreshed. Counter will always be >1 when the skin is refreshed. it will only take the defined action once when the skin is refreshed, both because IfCondition must change from "false" to "true" to fire again, and because we have UpdateDivider=-1 on the measure, so it just goes to sleep after the first skin update anyway.

2.jpg
3.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 19287
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using Counter for Skin "OnLoadAction"

jsmorley » January 31st, 2016, 12:22 pm

Brian,

"We've always been at war with Eastasia" :D
User avatar
Brian
Developer
Posts: 1879
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Using Counter for Skin "OnLoadAction"

Brian » January 31st, 2016, 1:18 pm

jsmorley-1984.png
-Brian
You do not have the required permissions to view the files attached to this post.