It is currently August 8th, 2020, 6:01 am

Variable key as a variable [trick]

Tips and Tricks from the Rainmeter Community
User avatar
Active Colors
Moderator
Posts: 605
Joined: February 16th, 2012, 3:32 am

Variable key as a variable [trick]

Post by Active Colors »

In case you need to have a variable key based on another variable, this trick is for you.

While I do not have a real life example, I got interested if this can be achieved as a possible solution for this case. This will be useful particularily with having several include files with almost same keys with slight different that is based on some other variable.

For instance, you have variables Location and Price but you don't want to name your keys differently (with different locations, like BerlinPrice, FrankfurtPrice, ...) accross multiple include files and have it as a part of the current location:

Code: Select all

[Variables]
Location=Berlin
@include1=#Location#.inc

-- Berlin.inc --
[Variables]
#Location#Price1=5.00
So in order to reference to this, you simply use this nested variable form:

Code: Select all

[Price1]
Meter=String
Text=Price: [##*Location*#Price1]
Capture.PNG
If you want to establish such a key=value pair you will need to use such kind of bang (for example on skin refresh):

Code: Select all

[Rainmeter]
OnRefreshAction=[!SetVariable "[#Location]Price" "[##*Location*#Price]"][!Update]
Capture.PNG
You do not have the required permissions to view the files attached to this post.