It is currently April 20th, 2024, 3:04 am

"Toggling" variables

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

"Toggling" variables

Post by jsmorley »

These are some nice examples from user Smurfier, that show how you can use !SetVariable to toggle and otherwise control variables.

Code: Select all

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

[Variables]
State=0

a=0
b=3

c=27
d=27
e=5

f=0
g=10

[MeterToggleState]
;Toggle variable "State" between 0 and 1
Meter=String
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Var State=#State#
DynamicVariables=1
LeftMouseUpAction=[!SetVariable State (1-#State#)][!UpdateMeter *][!Redraw]

[MeterToggleNumberZero]
;Toggle a number "a" between "b" and "0"
Meter=String
Y=10R
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Var a=#a# Var b=#b#
DynamicVariables=1
LeftMouseUpAction=[!SetVariable a (#b#-#a#)][!UpdateMeter *][!Redraw]

[MeterToggleTwoNumbers]
;Toggle a number "c" between two numbers "d" and "e"
Meter=String
Y=5R
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Var c=#c# Var d=#d# Var e=#e#
DynamicVariables=1
LeftMouseUpAction=[!SetVariable c (#d#+#e#-#c#)][!UpdateMeter *][!Redraw]

[MeterIncrementNumber]
;Increment a number "f" by one, to a maximum of "g", then start over
Meter=String
Y=5R
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Text=Var f=#f# Var g=#g#
DynamicVariables=1
LeftMouseUpAction=[!SetVariable f (#f#%#g#+1)][!UpdateMeter *][!Redraw]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: "Toggling" variables

Post by jsmorley »

Toggle the "visibility" of a meter.

Code: Select all

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

[Variables]
White=255,255,255
MyAlpha=255

[MeterTest]
Meter=Image
W=100
H=100
SolidColor=#White#,255
DynamicVariables=1
LeftMouseUpAction=[!SetVariable MyAlpha "(1+255-#MyAlpha#)"][!SetOption #CURRENTSECTION# SolidColor "#White#,#*MyAlpha*#"][!UpdateMeter #CURRENTSECTION#][!Redraw]

[MeterTest2]
Meter=Image
X=5R
W=100
H=100
SolidColor=#White#,255
DynamicVariables=1
LeftMouseUpAction=[!SetVariable MyAlpha "(1+255-#MyAlpha#)"][!SetOption #CURRENTSECTION# SolidColor "#White#,#*MyAlpha*#"][!UpdateMeter #CURRENTSECTION#][!Redraw]
The key to this is "escaping" the value for #MyAlpha# as #*MyAlpha*# that you use with !SetOption in the bang, so that you explicitly set the alpha to either 1 or 255, rather than relying on the variable. That will make it so multiple meters can share the variable, without them all changing at once.