Page 1 of 2

Help with !SetVariable

Posted: January 31st, 2021, 3:46 pm
by Xdominanta
Please tell me why this code does not work. instead of value it writes # mytest #
[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
;mytest=1

[MeterMyVar]
Meter=String
!SetVariable mytest "0"
Text=Value #mytest#
FontColor=255,255,255,90
DynamicVariables=1

Re: Help with !SetVariable

Posted: January 31st, 2021, 4:15 pm
by jsmorley
!Bangs are used as the result of some "action", and can't simply be used on their own. In addition, Meters can't have an "action". That must be done in the context of a Measure (or the Rainmeter) section of the skin.

Measures are the components that "measure" or "act". Meters can only "display".

https://docs.rainmeter.net/manual/bangs/
https://docs.rainmeter.net/manual/skins/option-types/#Action

So like this for example:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
mytest=1

[MeasureUpdateValue]
Measure=Calc
Formula=#mytest#
DynamicVariables=1
IfCondition=MeasureUpdateValue = 1
IfTrueAction=[!SetVariable mytest "0"]

[MeterMyVar]
Meter=String
Text=Value #mytest#
FontColor=255,255,255,90
DynamicVariables=1 
Now as written this is not particularly useful. The Calc measure I added is only to demonstrate how you use !Bangs in the context of some "action".

Re: Help with !SetVariable

Posted: January 31st, 2021, 5:19 pm
by Xdominanta
Thank you very much!

Re: Help with !SetVariable

Posted: January 31st, 2021, 5:20 pm
by balala
jsmorley wrote: January 31st, 2021, 4:15 pm !Bangs are used as the result of some "action", and can't simply be used on their own. In addition, Meters can't have an "action". That must be done in the context of a Measure (or the Rainmeter) section of the skin.
Or a meter can have a mouse action. For instance:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
mytest=1

[MeterMyVar]
Meter=String
Text=Value #mytest#
FontColor=255,255,255,90
SolidColor=0,0,0,1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable mytest "0"][!UpdateMeter "MeterMyVar"][!Redraw]
In this case the mytest variable gets the new value (0), when you click the meter (the old value of the variable, 1 in this case).

Re: Help with !SetVariable

Posted: January 31st, 2021, 5:53 pm
by jsmorley
balala wrote: January 31st, 2021, 5:20 pm Or a meter can have a mouse action. For instance:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
mytest=1

[MeterMyVar]
Meter=String
Text=Value #mytest#
FontColor=255,255,255,90
SolidColor=0,0,0,1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable mytest "0"][!UpdateMeter "MeterMyVar"][!Redraw]
In this case the mytest variable gets the new value (0), when you click the meter (the old value of the variable, 1 in this case).
Correct...

Re: Help with !SetVariable

Posted: February 6th, 2021, 7:05 pm
by Xdominanta
:) I'm probably not the best student, but could you please explain why !SetOption in the commented section works, but
!SetVariable no
[Rainmeter]
Update=1000
Author=Strannyuga
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Variables]
ColorFont=164,157,138
ColorUseCPU=80,200,120
ColorSeparator=255,165,0
SizeFont=32
LevelLoadCPU=1

;@include=#@#Variables.inc

;-------------------------------------------------------------
;Measure
;-------------------------------------------------------------
;[MeasureCPU]
;Measure=CPU
;Processor=0
;IfCondition=MeasureCPU < 1
;IfTrueAction=[!SetOption MeterValueCPU FontColor "80,200,120" ]
;IfCondition2=(MeasureCPU >= 2) && (MeasureCPU <= 3)
;IfTrueAction2=[!SetOption MeterValueCPU FontColor "255,165,0" ]
;IfCondition3=MeasureCPU > 4
;IfTrueAction3=[!SetOption MeterValueCPU FontColor "255,0,0" ]

[MeasureCPU]
Measure=CPU
Processor=0
IfCondition=MeasureCPU < 1
IfTrueAction=[!SetVariable LevelLoadCPU "1" ]
IfCondition2=(MeasureCPU >= 2) && (MeasureCPU <= 3)
IfTrueAction2=[!SetVariable LevelLoadCPU "2" ]
IfCondition3=MeasureCPU > 4
IfTrueAction3=[!SetVariable LevelLoadCPU "3" ]

;-------------------------------------------------------------
;Meter
;-------------------------------------------------------------
[MeterLabelCPU]
Meter=String
StringAlign=Left
FontFace=BIRTH OF A HERO
FontColor=#ColorFont#
FontSize=#SizeFont#
X=0
Y=(0.062*#SizeFont#)
Text=CPU
AntiAlias=1
UpdateDivider=-1

[MeterSeparator]
Meter=String
StringAlign=Left
FontFace=BIRTH OF A HERO
FontColor=#ColorSeparator#
FontSize=#SizeFont#
X=(2.19*#SizeFont#)
Y=0
Text=:
AntiAlias=1
UpdateDivider=-1

[MeterValueCPU]
Meter=String
MeasureName=MeasureCPU
StringAlign=Left
FontFace=BIRTH OF A HERO
FontColor=#ColorUseCPU#
FontSize=#SizeFont#
X=(2.82*#SizeFont#)
Y=(0.062*#SizeFont#)

Text="%1% --> #LevelLoadCPU#"
Percentual=1
AntiAlias=1

Re: Help with !SetVariable

Posted: February 6th, 2021, 7:29 pm
by balala
Xdominanta wrote: February 6th, 2021, 7:05 pm I'm probably not the best student, but could you please explain why !SetOption in the commented section works, but
!SetVariable no
Because when you set a variable with a !SetVariable bang, you have to set on the dynamic variables onto any measure or meter where you want to use the variable, adding a DynamicVariables=1 option. !SetOption does work even if you don't add the DynamicVariables option, because Rainmeter sets the appropriate measure or meter dynamic for one update cycle, even if you explicitely don't add the option.
So long story short, add the DynamicVariables=1 option to the [MeterValueCPU] meter if you want to use the dynamically set variable onto it. Don't add it, if you set dynamically an option (through the !SetOption bang).

Re: Help with !SetVariable

Posted: February 6th, 2021, 7:40 pm
by Xdominanta
Thanks!

Re: Help with !SetVariable

Posted: February 6th, 2021, 7:47 pm
by balala
Xdominanta wrote: February 6th, 2021, 7:40 pmThanks!
You're welcome.

Re: Help with !SetVariable

Posted: February 7th, 2021, 7:48 pm
by Xdominanta
Well! Thanks to your help, we managed to decorate my desktop a little. Thank you very much!
Image