Nesting Variables


There may be times when you want to embed or 'nest' variables within variables. This might include any combination of #Variables#, #Built-InVariables#, [SectionVariables] or $MouseVariables$.

So for instance, the goal might be to have things like:

Text=#MyVar#MyOtherVar##
Text=#MyVar[MyMeasure]#
Text=[MyMeasure#MyVar#]
Text=[MyMeasure[MyOtherMeasure]]

This creates ambiguities that simply can't be reliably parsed and understood by Rainmeter, and can't work.

Rainmeter solves this by having an alternative form of these variables. These function exactly as their normal counterparts do, but can successfully be nested.

The alternative Nesting Variables syntax

[#VarName]   Replaces: #VarName#
[&MeasureName]   Replaces: [MeasureName]
[$MouseVar]   Replaces: $MouseVar$


So our examples above would look like:

Text=[#MyVar[#MyOtherVar]]
Text=[#MyVar[&MyMeasure]]
Text=[&MyMeasure[#MyVar]]
Text=[&MyMeasure[&MyOtherMeasure]]

Notes:

It is not suggested that this in any way deprecates the current style of using variables in your skin. This is an alternative way, that simply allows for nesting to be successful. Use them all the time, or use them just when needed, that is a matter of personal preference.

One difference is that when the Nesting Variables syntax is used in bangs, the values are always dynamically resolved when they are used, including in the [Rainmeter] section of the skin. This is different than the standard #VarName# syntax, which will always require DynamicVariables=1 when the value changes, and can't be dynamic in [Rainmeter]. This difference only applies to use in bangs. When used in option values, DynamicVariables=1 must still be set on the measure or meter if the value changes.

If you are escaping a variable and need to use the nested form, the syntax is:

[#*VarName*]
[&*MeasureName*]

Examples

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

[Variables]
Var1=One
Var2=Two

[MeasureStringOne]
Measure=String
String="I'm the first Measure"

[MeasureStringTwo]
Measure=String
String="I'm the second Measure"

[MeterTest1]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&MeasureString[#Var1]]#CRLF#[&MeasureString[#Var2]]
DynamicVariables=1

[MeasureNum3]
Measure=Calc
Formula=3

[MeasureNum4]
Measure=Calc
Formula=4

[MeasureString3]
Measure=String
String="I'm the third Measure"

[MeasureString4]
Measure=String
String="I'm the fourth Measure"

[MeterTest2]
Meter=String
Y=10R
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&MeasureString[&MeasureNum3]]#CRLF#[&MeasureString[&MeasureNum4]]
DynamicVariables=1
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=1
HighBound=5
UpdateRandom=1
UniqueRandom=1

[Measure1]
Measure=String
String="I'm One"

[Measure2]
Measure=String
String="I'm Two"

[Measure3]
Measure=String
String="I'm Three"

[Measure4]
Measure=String
String="I'm Four"

[Measure5]
Measure=String
String="I'm Five"

[MeterTest1]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&Measure[&MeasureRandom]]
DynamicVariables=1
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
XPos1=15
XPos2=10
XPos3=30
XPos4=100
XPos5=0

[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=1
HighBound=5
UpdateRandom=1
UniqueRandom=1

[MeterTest1]
Meter=String
X=[#XPos[&MeasureRandom]]
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Hello World
DynamicVariables=1

Download Examples

You can download the above examples as a .rmskin.