MerlinTheRed wrote:Code: Select all
[!WriteKeyValue Variables Drive #Drive"#DriveNow#"# #CURRENTPATH##CURRENTFILE#]
I assume that is the magic part. But I don't quite get it. Can you use double quotes to insert a variable's value into a variable name? That's important for me right now because if this really works, I could avoid using a Lua script for a certain task. Is this feature documented somewhere?
There's nothing magical about this.
The following snippet...
... is parsed as follows:
1) Attempt to expand variable #Drive"# (which fails because no such variable exists)
2) Attempt to expand variable #DriveNow# (which succeeds)
3) The last # is unmatched, no action is taken
Now.. Why do the quotes disappear? When Rainmeter finds a parameter for a
bang, all double quotes in the parameter are discarded. This happens after the variables have been expanded, which is why this works.
Had you used...
.. the situation would be:
1) Attempt to expand variable #Drive#, which succeeds (the string would be C#DriveNow## or similar at this point)
2) Attempt to expand variable #DriveNow#, which succeeds (the string would be C1# or similar at this point)
3) The last # is unmatched, no action is taken
MerlinTheRed wrote:So if I have a series of variables like:
Code: Select all
[Variables]
CurrentString=2
String1="SomeTextOne"
String2="SomeTextTwo"
String3="SomeTextThree"
...
And I want to reference these images based on the value of a variable
Code: Select all
[MeterString]
Meter=String
Text=#String"#CurrentString#"#
that won't work.
Let's think about the following snippet:
Rainmeter will attempt to expand as follows:
1) #String"# (fails)
2) #CurrentString# (succeeds)
3) The last # is unmatched, no action is taken
So you're left with #String"2"# (and since matching is a left-to-right process, Rainmeter won't be even attempt to expand this). Why are the quotes there? Because they are stripped only in matched bang parameters (that's why bang was in bold).
MerlinTheRed wrote:This won't work either:
Code: Select all
[SomeMeasure]
Measure=Calc
Formula=2
[MeterString]
Meter=String
MeasureName=SomeMeasure
Text=#String%1#
Display: SomeTextTwo
IIRC, Rainmeter will first attempt to expand the variable #String%1# (fails). Then %1 is replaced with the value of the measure. The first step is done the first update (or every update if DynamicVariables=1). The last step is done on every update.
Kaelri wrote:I think a more "correct" way would be to use escape characters for the containing variable, as in
Code: Select all
LeftMouseUpAction=!Execute [!WriteKeyValue Variables Drive #*Drive#DriveNow#*#]
I don't think that will work with how escape is parsed right now:
1) Attempt to expand variable #*Drive# (since the next # is not preceeded with *), which fails
2) Attempt to expand variable #DriveNow#, which succeeds
...
Perhaps it would be better to change the escape routine to find the next *# (not just #) when #* is met.