eclectic-tech wrote: ↑August 22nd, 2020, 11:45 amBy changing how variables are defined, you can get the desired results, but this will get more complicated as you increase the number of variable-dependent variables.
Many thanks for pointing me in the right direction, as this code works without issues:
Code: Select all
[Variables]
String1="string"
String2="A [#String1] is made out of characters"
String3="[#String2] and it has a length."
String4="[#String3] Period."
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255
---Measures---
[MeasureToggler]
Measure=Calc
Formula=(1-MeasureToggler)
UpdateDivider=-1
RegExpSubstitute=1
Substitute="^0$":"string","^1$":"text"
DynamicVariables=1
---Meters---
[MeterTest]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="String1 Format = either 'string' or 'text' (click based, dynamic)#CRLF#String2 Format = 'A [#*String1*] is made out of characters'#CRLF#String3 Format = '[#*String2*] and it has a length.'#CRLF##CRLF#String1 = #String1##CRLF#String2 = #String2##CRLF#String3 = #String3##CRLF#String4 = #String4#"
LeftMouseUpAction=[!UpdateMeasure *][!SetVariable String1 "[MeasureToggler]"][!SetVariable String2 "A [#String1] is made out of characters"][!SetVariable String3 "[#String2] and it has a length."][!UpdateMeter *][!Redraw]
DynamicVariables=1
Of course, as you said, it becomes more complex and the number of bangs required increase once you increase the number of variable-dependent variables. Also, it requires you to set each variable again each time a change is made to the lowest level variable (i.e. String1), as it can be seen above, where String4 doesn't update unless a
[!SetVariable String4 "[#String3] Period."] bang is added as well. Although the method works (lots of thanks for that!) it's quite a pain to apply it in a "real-life" scenario in a skin. For example, I have my weather variables (mainly regex patterns) set like this:
Code: Select all
; Site Mode: EscB=\\ <-> API Mode: EscB=
EscB=\\
Q=#EscB#"
EscQ=#EscB##EscB#\\"
Cleaner="(?:^[^[\x200B]].*|.*[^[\x200B]]$)":"","(?:^[\x200B]|[\x200B]$)":"","(?:^\\\d+|\\\d+$)":""
Decoder="[\\]+"":"""
; General Patterns
Flag=(?siU)
Lead=(?>.*#Q#[^"]*dailyforecast#Q#:\[|.*#Q#[^"]*data#Q#:|)
Stop=(?>,|\{|\[|\]|\}|$)
Data=(?:[^"\{\[\]\}]*|(?:(?>#EscQ#|[^"])*#Q#){2}+)
; Source Data
Weather=^(.*)$
; Weather
Location=#Q#[^"]*location[^"]*#Q#:[^\}]*([\{\[]{1}[^\}]*#Q#[^"]*city[^"]*#Q#:\s*#Q#[^"]+#Q#.*[\]\}]{2})
Observation=#Q#[^"]*observation[^"]*#Q#:[^\}]*([\{\[]{1}.*[\]\}]{1})
DateTime=#Q#[^"]*datetime[^"]*#Q#:[^\}]*([\{\[]{1}.*[\]\}]{1})
DailyForecast=#Q#(?=[^"]*daily)(?=[^"]*forecast)[^"]*#Q#:(?:(?=.*15day).*15day|)[^\}]*([\{\[]{1}.*[\]\}]{3,4}+)
; Weather -> Location
Latitude=#Q#[^"]*latitude[^"]*#Q#:
Longitude=#Q#[^"]*longitude[^"]*#Q#:
City=#Q#[^"]*city#Q#:
District=#Q#[^"]*district#Q#:
DistrictCode=#Q#[^"]*districtcode[^"]*#Q#:
Country=#Q#[^"]*country#Q#:
CountryCode=#Q#[^"]*countrycode[^"]*#Q#:
; Weather -> Observation
Units=[:;]units:
Pressure=#Q#[^"]*altimeter[^"]*#Q#:
PressureCode=#Q#[^"]*(?:barometer|pressure)[^"]*code[^"]*#Q#:
PressureChange=#Q#[^"]*(?:barometer|pressure)[^"]*change[^"]*#Q#:
DewPoint=#Q#[^"]*dewpoint[^"]*#Q#:
FeelsLike=#Q#[^"]*feelslike[^"]*#Q#:
WindGust=#Q#[^"]*gust[^"]*#Q#:
HumidityPercent=#Q#[^"]*humidity[^"]*#Q#:
Icon=#Q#[^"]*icon(?:code)?#Q#:
ObservationTime=#Q#(?:[^"]*(?:observation|valid)time[^"]*)(?<!utc)#Q#:
Phrase=#Q#(?:wx)?phrase(?:long)?#Q#:
Precipitation24Hours=#Q#[^"]*precip24h[^"]*#Q#:
Snow24Hours=#Q#[^"]*snow(?:depth|24h)[^"]*#Q#:
Temperature=#Q#[^"]*temperature#Q#:
UltravioletIndex=#Q#[^"]*uvindex[^"]*#Q#:
Visibility=#Q#[^"]*visibility[^"]*#Q#:
WindSpeed=#Q#[^"]*windspeed[^"]*#Q#:
WindDirection=#Q#[^"]*winddir[^"]*(?-i)C[^"]*#Q#:
; Weather -> DateTime
TimeZone=#Q#[^"]*timezoneabbr[^"]*#Q#:
; Weather -> DailyForecast
ValidDate=#Q#(?:[^"]*valid(?:date|time)[^"]*)(?<!utc)#Q#:
DayOfWeek=#Q#[^"]*dayofweek[^"]*#Q#:
Sunrise=#Q#(?:[^"]*sunrise[^"]*)(?<!utc)#Q#:
Sunset=#Q#(?:[^"]*sunset[^"]*)(?<!utc)#Q#:
MoonCode=#Q#[^"]*moon[^"]*(?:icon|code)#Q#:
Moonrise=#Q#(?:[^"]*moonrise[^"]*)(?<!utc)#Q#:
Moonset=#Q#(?:[^"]*moonset[^"]*)(?<!utc)#Q#:
; Weather -> DailyForecast -> DayPart
PrecipitationPercent=#Q#[^"]*precip(?:pct|chance)[^"]*#Q#:
PrecipitationAmount=#Q#[^"]*(?:precipamt[^"]*|qpf)#Q#:
PrecipitationType=#Q#[^"]*preciptype[^"]*#Q#:
; Note: the Temperature, Ultraviolet Index, Icon, Phrase are like in Weather -> Observation, thus skipped
CloudPercent=#Q#[^"]*cloud(?:pct|cover)[^"]*#Q#:
; Note: the Wind Speed / Direction, Humidity are like in Weather -> Observation, thus skipped
Qualifier=#Q#[^"]*qualifier(?:phrase)?#Q#:
SnowRange=#Q#[^"]*snowrange[^"]*#Q#:
I already automated the process of of switching from the Site mode to the API mode and back a while ago, by checking if an API Key has been added in a corresponding measure using an IfMatch, but I want to similarly automate the escaped (Site mode) vs unescaped (API mode) quote format as well, in the same measure, by "updating" all these variables when changing the
EscB variable (which holds the escaped backslash,
\\ for the Site mode and nothing aka empty string for the API mode) using a bang instead of having to modify it manually by editing the file. You can imagine the effort of writing a TON of bangs for such a thing to happen - and my skin is extremely light in terms of measures and meters, compared to other weather skins, due to how I built it...
eclectic-tech wrote: ↑August 22nd, 2020, 11:45 amI agree that this would be a popular addition, but it definitely would break backward compatibility.
Hmm. What are you referring to, more specifically? To the fact that variables are strongly linked to updating measures, meters or options calling for their resolve? Or to the fact that they are read only on those updates and don't exist in Rainmeter's memory (where they could easily be updated and have those changes reflected in the skin)?
EDIT: You were right - I only had to turn
EscB from a variable into a String measure, set:
in the
[Variables] section and then instead of setting the variable, set the
String option of the newly created
[EscB] measure. It all works flawlessly now - many thanks again.
I will not yet mark the thread as solved as I would be interested to find out what the devs think about these things, but I might mark it afterwards.