**http://docs.rainmeter.net/manual-beta/measures/loop**

**The problem**

Currently, creating a looping "counter" in Rainmeter is done with a Calc measure and a modulo mathematical function:

Code: Select all

```
[MeasureName]
Measure=Calc
Formula=(MeasureName % 100) + 1
```

1) The "starting" value of the counter can't easily be "0", or really any number other than "1".

2) It is difficult to increment by other than "1", as that impacts the starting value as well.

3) It is difficult to count "backwards".

4) You must manually set MinValue and MaxValue to use as a percentage.

5) This can only create an "endless" loop, you can't loop 3 times and stop for instance.

6) Overall, the function is not very intuitive to new or non-programmer Rainmeter users.

**The solution**

The new Loop measure can be used in place of this modulo approach. The way it works is:

The measure will be the value of StartValue for one update, will increment based on the value of Increment on each subsequent update, and will be the value of EndValue for one update. If LoopCount is other than 1, the loop will then repeat.

A couple of simple examples might be:

Code: Select all

```
[MeasureLoop]
Measure=Loop
StartValue=0
EndValue=50
Increment=1
LoopCount=0
```

Code: Select all

```
[MeasureLoop]
Measure=Loop
StartValue=100
EndValue=0
Increment=-10
LoopCount=1
```

**Additional features**

If you set InvertMeasure=1 on the measure, the value that is returned is the "opposite" of the measured value. This has the effect of "counting backwards", with no other change to the measure options required.

The measure can be reset and will start over with all current option values when the !CommandMesasure MeasureName "Reset" bang is sent to the measure.

**Some rules**

There are some rules for how this measure works that should be kept in mind:

1) All options must be positive or negative whole numbers, or formulas that resolve to whole numbers. Fractional values will be truncated.

2) The measure will have a range that is the difference between StartValue and EndValue for use by meters requiring a percentage. There cannot be a negative percentage, so the range will always be lowest value to highest value. MinValue will be set to the lower of StartValue / EndValue, and MaxValue will be set to the higher of StartValue / EndValue.

3) Any dynamic change to any of the four measure options, or dynamically changing InvertMeasure on the measure, will cause the loop to be reset and start over with the new values.

**Examples**

First, here is a .rmskin that has all the example skins included:

AlphaLoop:

Code: Select all

```
[Rainmeter]
Update=20
DynamicWindowSize=1
AccurateText=1
[MeasureAlpha]
Measure=Loop
StartValue=30
EndValue=255
Increment=20
LoopCount=1
Paused=1
[MeterAlpha]
Meter=String
MeasureName=MeasureAlpha
W=154
H=50
X=77
StringAlign=Center
FontSize=35
FontColor=255,255,255,[MeasureAlpha]
SolidColor=30,40,50,[MeasureAlpha]
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
MouseOverAction=[!SetOption MeasureAlpha InvertMeasure 0][!UnpauseMeasure MeasureAlpha]
MouseLeaveAction=[!SetOption MeasureAlpha InvertMeasure 1]
```

BarLoop:

Code: Select all

```
[Rainmeter]
Update=500
DynamicWindowSize=1
AccurateText=1
[Variables]
Invert=0
[MeasureLoop]
Measure=Loop
StartValue=-50
EndValue=50
Increment=5
LoopCount=0
InvertMeasure=#Invert#
DynamicVariables=1
[MeterLoopBar]
Meter=Bar
MeasureName=MeasureLoop
W=400
H=20
BarColor=74,143,186,255
SolidColor=47,47,47,255
BarOrientation=Horizontal
[MeterLoopValue]
Meter=String
MeasureName=MeasureLoop
X=10
Y=2
FontSize=11
FontColor=255,255,255,255
AntiAlias=1
[MeterLoopPercent]
Meter=String
MeasureName=MeasureLoop
X=390
Y=2
StringAlign=Right
FontSize=11
FontColor=255,255,255,255
AntiAlias=1
Percentual=1
Text=%1%
[MeterBackwards]
Meter=String
X=0
Y=10R
W=70
H=16
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Backwards
LeftMouseUpAction=[!SetVariable Invert 1]
[MeterForwards]
Meter=String
X=0
Y=5R
W=70
H=16
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Forwards
LeftMouseUpAction=[!SetVariable Invert 0]
[MeterToggle]
Meter=String
X=0
Y=5R
W=70
H=16
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toggle
LeftMouseUpAction=[!SetVariable Invert (1-#Invert#)]
DynamicVariables=1
```

Click to view animation: ImageLoop:

Code: Select all

```
[Rainmeter]
Update=250
DynamicWindowSize=1
AccurateText=1
[Variables]
Start=0
End=9
Incr=1
[MeasureLoop]
Measure=Loop
StartValue=#Start#
EndValue=#End#
Increment=#Incr#
LoopCount=1
[MeasurePingPong]
Measure=Calc
IfCondition=MeasureLoop >= #End#
IfTrueAction=[!SetOption MeasureLoop InvertMeasure 1][!UpdateMeasure MeasureLoop]
IfCondition2=MeasureLoop <= #Start#
IfTrueAction2=[!SetOption MeasureLoop InvertMeasure 0][!UpdateMeasure MeasureLoop]
Disabled=1
[MeterImage]
Meter=Image
ImagePath=#@#GifFrames\
ImageName=Frame[MeasureLoop].png
DynamicVariables=1
[MeterOnceForward]
Meter=String
Y=10R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Once Forward
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop InvertMeasure 0][!SetOption MeasureLoop LoopCount 1][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset]
[MeterOnceBackward]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Once Backward
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop InvertMeasure 1][!SetOption MeasureLoop LoopCount 1][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset]
[MeterRepeat]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Repeat Current Direction
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop LoopCount 0][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset]
[MeterPingPong]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=PingPong
LeftMouseUpAction=[!UnpauseMeasure MeasureLoop][!EnableMeasure MeasurePingPong]
[MeterTogglePause]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toggle Pause
LeftMouseUpAction=[!TogglePauseMeasure MeasureLoop]
```

RoundLoop:

Code: Select all

```
[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1
[Variables]
Start=0
End=360
Incr=4
Loop=0
Invert=0
[MeasureLoop]
Measure=Loop
StartValue=#Start#
EndValue=#End#
Increment=#Incr#
LoopCount=#Loop#
InvertMeasure=#Invert#
DynamicVariables=1
[MeterRoundline1]
Meter=Roundline
X=0
Y=0
W=130
H=130
LineColor=178,221,240,255
Solid=1
LineStart=55
LineLength=65
StartAngle=(0-(Rad([MeasureLoop])))
RotationAngle=(0-(Rad(180)))
AntiAlias=1
SolidColor=0,0,0,1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Invert (1-#Invert#)][!UpdateMeasure MeasureLoop]
[MeterRoundline2]
Meter=Roundline
X=0
Y=0
W=130
H=130
LineColor=254,222,135,255
Solid=1
LineStart=40
LineLength=50
StartAngle=(Rad([MeasureLoop]))
RotationAngle=(Rad(180))
AntiAlias=1
DynamicVariables=1
[MeterRoundline3]
Meter=Roundline
X=0
Y=0
W=130
H=130
LineColor=230,103,96,255
Solid=1
LineStart=25
LineLength=35
StartAngle=(0-(Rad([MeasureLoop])))
RotationAngle=(0-(Rad(180)))
AntiAlias=1
DynamicVariables=1
[MeterRoundline4]
Meter=Roundline
X=0
Y=0
W=130
H=130
LineColor=196,218,135,255
Solid=1
LineStart=10
LineLength=20
StartAngle=(Rad([MeasureLoop]))
RotationAngle=(Rad(180))
AntiAlias=1
DynamicVariables=1
```

StringLoop:

Code: Select all

```
[Rainmeter]
Update=300
DynamicWindowSize=1
AccurateText=1
[Variables]
Start=0
End=10
Incr=1
[MeasureLoop]
Measure=Loop
StartValue=#Start#
EndValue=#End#
Increment=#Incr#
LoopCount=1
[MeasurePingPong]
Measure=Calc
IfCondition=MeasureLoop = #End#
IfTrueAction=[!SetOption MeasureLoop InvertMeasure 1][!UpdateMeasure MeasureLoop]
IfCondition2=MeasureLoop = #Start#
IfTrueAction2=[!SetOption MeasureLoop InvertMeasure 0][!UpdateMeasure MeasureLoop]
Disabled=1
[MeterString]
Meter=String
MeasureName=MeasureLoop
W=154
H=50
X=77
StringAlign=Center
FontSize=35
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
[MeterOnceForward]
Meter=String
Y=10R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Once Forward
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop InvertMeasure 0][!SetOption MeasureLoop LoopCount 1][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset][!UpdateMeasure MeasureLoop]
[MeterOnceBackward]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Once Backward
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop InvertMeasure 1][!SetOption MeasureLoop LoopCount 1][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset][!UpdateMeasure MeasureLoop]
[MeterRepeat]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Repeat Current Direction
LeftMouseUpAction=[!DisableMeasure MeasurePingPong][!SetOption MeasureLoop LoopCount 0][!UnpauseMeasure MeasureLoop][!CommandMeasure MeasureLoop Reset][!UpdateMeasure MeasureLoop]
[MeterPingPong]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=PingPong
LeftMouseUpAction=[!UnpauseMeasure MeasureLoop][!EnableMeasure MeasurePingPong]
[MeterTogglePause]
Meter=String
Y=3R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Toggle Pause
LeftMouseUpAction=[!TogglePauseMeasure MeasureLoop]
```