It is currently April 17th, 2021, 2:44 am

Help with !SetVariable

Get help with installing and using Rainmeter.
User avatar
Xdominanta
Posts: 8
Joined: January 31st, 2021, 3:38 pm

Help with !SetVariable

Post 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
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with !SetVariable

Post 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".
User avatar
Xdominanta
Posts: 8
Joined: January 31st, 2021, 3:38 pm

Re: Help with !SetVariable

Post by Xdominanta »

Thank you very much!
User avatar
balala
Rainmeter Sage
Posts: 12566
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with !SetVariable

Post 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).
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with !SetVariable

Post 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...
User avatar
Xdominanta
Posts: 8
Joined: January 31st, 2021, 3:38 pm

Re: Help with !SetVariable

Post 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
User avatar
balala
Rainmeter Sage
Posts: 12566
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with !SetVariable

Post 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).
User avatar
Xdominanta
Posts: 8
Joined: January 31st, 2021, 3:38 pm

Re: Help with !SetVariable

Post by Xdominanta »

Thanks!
User avatar
balala
Rainmeter Sage
Posts: 12566
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with !SetVariable

Post by balala »

Xdominanta wrote: February 6th, 2021, 7:40 pmThanks!
You're welcome.
User avatar
Xdominanta
Posts: 8
Joined: January 31st, 2021, 3:38 pm

Re: Help with !SetVariable

Post by Xdominanta »

Well! Thanks to your help, we managed to decorate my desktop a little. Thank you very much!
Image