It is currently December 10th, 2018, 6:32 pm

set Variables values

Get help with installing and using Rainmeter.
Den Duze
Posts: 12
Joined: September 14th, 2018, 9:13 am

set Variables values

Den Duze » September 18th, 2018, 12:32 pm

Hi,

I've read that I must use DynamicVariables=1 if i want to use variables in meters/measures where the values can change during the running of the skin.
But the variable that I need do not change, they will be set once and I want to use them in different ways.
So I tried with the following structure:
[MeasureOSVersion]
Measure=Plugin
Plugin=SysInfo
SysInfoType=OS_VERSION
UpdateDivider=-1

[Variables]
OsVersion=MeasureOSVersion

But it looks like this does not work.
Can I initial assing a value to a variable with the result of a measure?

Can I use something like the following;
PathName=C:\@Resources\Files\<Variable>.txt
or wil that not work with a variable?
it works with: PathName=@Resources\Files\%COMPUTERNAME%.txt but I wonder if I can do the same with a variable (or do i also need to use DynamicVariable in that case.

Remark: when I look to the About-screen - Skins and select my skin I can see the Variables.
Should that always show the real value of the variable? Also when I set it like OsVersion=MeasureOSVersion because in that case I see the value MeasureOSVersion

Regards
Ddier
User avatar
jsmorley
Developer
Posts: 18444
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: set Variables values

jsmorley » September 18th, 2018, 12:48 pm

It's important to know that variables in and of themselves are never "dynamic". They are always simply a string that you assign to a variable name. If you set MyVar=[SomeMeasure], the value of the variable MyVar is literally "[SomeMeasure]", not the value of the measure SomeMeasure.

it's not the [Variables] section that resolves things. It's where you "use them" that does that work.

So let's take an example:

Code: Select all

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

[Variables]
MyVar=[MyMeasure]

[MyMeasure]
Measure=Calc
Formula=MyMeasure +1

[MyMeter]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=#MyVar#
DynamicVariables=1
While this isn't a useful example, as there really is no need to use a variable for this, it does illustrate how variables work.

- You set the value of the variable MyVar to the section variable [MyMeasure].
- The measure MyMeasure is counting on every skin update.
- The value of the variable MyVar will STAY the literal string "[MyMeasure]" and will never change. Variables are never "dynamic".
- However, when you use that variable in a String meter, with DynamicVariables=1 set on it, when that literal string "[MyMeasure]" is seen, it is resolved by the String meter itself, and will display the current value of the measure MyMeasure.
1.jpg

Note:
If you want to use the value of a measure somewhere, you need to use it as a section variable in the form [MeasureName]. What you have here:

Code: Select all

[Variables]
OsVersion=MeasureOSVersion
Can't work, as the variable OsVersion is set to the literal string "MeasureOSVersion". This will just be treated as a literal string, and not a reference to a measure value everywhere in Rainmeter, with two exceptions. In the Formula option of a Calc measure, and in an IfCondition test on any measure. This is because these are the only two cases where the only possible use of a string like that is a reference to a measure value, since strings can never be used in formulas.

So you need:

Code: Select all

[Variables]
OsVersion=[MeasureOSVersion]
https://docs.rainmeter.net/manual/variables/section-variables/
You do not have the required permissions to view the files attached to this post.
Den Duze
Posts: 12
Joined: September 14th, 2018, 9:13 am

Re: set Variables values

Den Duze » September 18th, 2018, 1:10 pm

Hi jsmorley,

Thanks I understand (I hope).
My idea was ok but it was just the way how I tried it that was wrong because I didn't know how the system works!
Thanks for making that a bit clearer.

It's a pity that in the About-screen - Skins you do not see the actual value of the [variable] but OK ...

Thanks
Didier
User avatar
jsmorley
Developer
Posts: 18444
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: set Variables values

jsmorley » September 18th, 2018, 1:12 pm

Note that I said my example, and to be honest your example, don't really require a variable at all...

So in my example both this:

Code: Select all

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

[MyMeasure]
Measure=Calc
Formula=MyMeasure +1

[MyMeter]
Meter=String
MeasureName=MyMeasure
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=The value is: %1
And this:

Code: Select all

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

[MyMeasure]
Measure=Calc
Formula=MyMeasure +1

[MyMeter]
Meter=String
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=The value is: [MyMeasure]
DynamicVariables=1
Would work fine, without needing to pass the value through a variable.
User avatar
jsmorley
Developer
Posts: 18444
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: set Variables values

jsmorley » September 18th, 2018, 1:13 pm

Den Duze wrote:Hi jsmorley,

Thanks I understand (I hope).
My idea was ok but it was just the way how I tried it that was wrong because I didn't know how the system works!
Thanks for making that a bit clearer.

It's a pity that in the About-screen - Skins you do not see the actual value of the [variable] but OK ...

Thanks
Didier
But you DO see the actual value of the [Variable]... ;-)

Again, variables are just strings. It's where you "use them" that can treat their value dynamically. It's not a flaw in the design, it's actually really well thought out. Only do the "work" where and when you need to do it.
Den Duze
Posts: 12
Joined: September 14th, 2018, 9:13 am

Re: set Variables values

Den Duze » September 18th, 2018, 1:25 pm

I know that in this example it's not really needed to use a variable but it's also just a part of the coding.
I want to use the same variable also in other places in the ini-file, so in that case I guess it's better to use a variable then always call the Measure-block to get that value back.
But now that I think of it, if I use it the way like suggested I probably always perform the Measure-Block when I use Text=#MyVar#?

regards
Didier
User avatar
jsmorley
Developer
Posts: 18444
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: set Variables values

jsmorley » September 18th, 2018, 1:27 pm

Den Duze wrote:I know that in this example it's not really needed to use a variable but it's also just a part of the coding.
I want to use the same variable also in other places in the ini-file, so in that case I guess it's better to use a variable then always call the Measure-block to get that value back.
But now that I think of it, if I use it the way like suggested I probably always perform the Measure-Block when I use Text=#MyVar#?

regards
Didier
That's right. Using a variable for this will never save anything, no matter where or how many times you reference the measure value. Each time you use #MyVar# dynamically, the measure or meter using that variable will get the current value of the measure referenced as a [SectionVariable] in the variable definition. It's not "executing" the measure or anything like that, just asking for its current value. Using [MyMeasure] dynamically instead does exactly the same thing, without requiring the extra code of creating a variable.

To be honest using a variable for this is just a tad "more" work, as it first has to resolve the value of the variable MyVar to the string "[MyMeasure]", then detect that this is a section variable, and go get the value of the measure. No need for two "steps" here.