It is currently March 28th, 2024, 8:09 pm

Some tricks with !SetVariable bang

Tips and Tricks from the Rainmeter Community
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Some tricks with !SetVariable bang

Post by ~Faradey~ »

Hello everyone!
I've learned a lot of things on this forum, so, let me to make a small contribution too :)
The major point of these tricks is to make code "shorter" + to decreasing number of measures and other stuff in skin, So lets begin.

Note: These tricks only works on latest beta r848!

1. A simple mathematical functions (about all available functions and operators you can read here )

addition
LeftMouseUpAction=!SetVariable a (#a#+1)
subtraction
LeftMouseUpAction=!SetVariable a (#a#-1)
multiplication
LeftMouseUpAction=!SetVariable a (#a#*2)
division
LeftMouseUpAction=!SetVariable a (#a#/2)
and so on...

1.1 Example

Code: Select all

[Variables]
a=100

[ExampleMeter]
Meter=Image
X=20
Y=0
W=100
H=#a#
SolidColor=128,128,128
AntiAlias=1
DynamicVariables=1

[ButtonPlus]
Meter=String
X=-20r
Y=r
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=10
FontFace=Webdings
Text="5"
AntiAlias=1
LeftMouseUpAction=!SetVariable a (#a#+5)
DynamicVariables=1

[ButtonMinus]
Meter=String
X=r
Y=15r
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=10
FontFace=Webdings
Text="6"
AntiAlias=1
LeftMouseUpAction=!SetVariable a (#a#-5)
DynamicVariables=1
2. Cyclic variable

!SetVariable a ((#a#+1)%#b#=0?#b#:(#a#+1)%#b#)
,where b is maximum value

2.1 Example

Code: Select all

[Variables]
a=1
b=3

[WebMeasure]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://rainmeter.net/forum/feed.php
RegExp="(?siU)</title>.*<title .*><(.*)></title>.*<title .*><(.*)></title>.*<title .*><(.*)></title>"
UpdateRate=800

[TestMaesure1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WebMeasure]
StringIndex=1
Substitute="![CDATA[":"","]]":""

[TestMaesure2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WebMeasure]
StringIndex=2
Substitute="![CDATA[":"","]]":""

[TestMaesure3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WebMeasure]
StringIndex=3
Substitute="![CDATA[":"","]]":""

[ExampleMeter]
Meter=String
MeasureName=TestMaesure1
MeasureName2=TestMaesure2
MeasureName3=TestMaesure3
X=0
Y=0
W=200
H=18
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=9
FontFace=Arial
Text="%#a#"
AntiAlias=1
DynamicVariables=1

[ButtonNext]
Meter=String
X=40r
Y=20r
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=12
FontFace=Webdings
Text="4"
AntiAlias=1
LeftMouseUpAction=!SetVariable a ((#a#+1)%#b#=0?#b#:(#a#+1)%#b#)
DynamicVariables=1
3. Toggle a variable

!SetVariable a (TRUNC((COS(#a#))))

3.1 Example

Code: Select all

[Variables]
a=1

[ExampleMeter]
Meter=String
X=20
Y=0
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=9
FontFace=Arial
Text="Toggling Anti-aliasing"
AntiAlias=#a#
DynamicVariables=1

[ButtonToggle]
Meter=String
X=-20r
Y=1r
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=10
FontFace=Webdings
Text="="
AntiAlias=1
LeftMouseUpAction=!SetVariable a (TRUNC((COS(#a#))))
DynamicVariables=1
4. Dynamic angle value of meter by using !SetVariable
In this case we need two !setvariable bangs

[!SetVariable r (#r#+10)][!SetVariable grad ((#r#/(180/PI)))]

4.1 Example

Code: Select all

[Variables]
r=90
; Angle in degrees

grad=1.57075
; Start state of angle

[ExampleMeter]
Meter=String
X=100
Y=100
W=190
H=14
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=9
FontFace=Arial
Text="I'm a Text"
AntiAlias=1
Angle=#grad#
DynamicVariables=1

[RotateButton]
Meter=String
X=40r
Y=40r
W=190
H=14
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=9
FontFace=Arial
Text="Rotate me!"
AntiAlias=1
DynamicVariables=1
LeftMouseUpAction=!execute [!SetVariable r (#r#+10)][!SetVariable grad ((#r#/(180/PI)))]
...this is only an examples...how else to use only your decision :)
Last edited by ~Faradey~ on July 5th, 2011, 11:26 pm, edited 1 time in total.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Some tricks with !SetVariable bang

Post by smurfier »

There is an easier way to use cyclical variables:
!SetVariable a (#a#%#b#+1)

To toggle a variable:
Between a certain number B and zero-
!Set Variable a (#b#-#a#)
Between two set numbers B and C-
!SetVariable a (#b#+#c#-#a#)
Last edited by smurfier on July 5th, 2011, 11:39 pm, edited 2 times in total.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Some tricks with !SetVariable bang

Post by ~Faradey~ »

smurfier wrote:There is an easier way to use cyclical variables:
!SetVariable a (#a#%#b#+1)

To toggle a variable:
Between a certain number B and zero-
!Set Variable a (#b#-#a#)
Between two set numbers B and C-
!SetVariable a (ABS((#b#+#c#)-#a#))
Ow, well, :confused: i'm not that smart) and i've tried my best)

Thanks for showing easier side :)
Ariex
Posts: 14
Joined: December 23rd, 2010, 1:33 pm
Location: Germany

Re: Some tricks with !SetVariable bang

Post by Ariex »

Hellolo,

I want use this Toggle Variable method to hide/show a meter, i tried it with Faradey's variant, !SetVariable a (TRUNC((COS(#a#)))), it works by AntiAlias, but not by Hidden.

Smurfiers Method works only when a=0, but this make no sense to me, i mean a starts as 0, b=1, i click on the button, and b is substracted from 0, so the value are still 0, but the meter is hidden, but if a=1 it don't work.

Im confused. :???:
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Some tricks with !SetVariable bang

Post by smurfier »

Ariex wrote: Smurfiers Method works only when a=0, but this make no sense to me, i mean a starts as 0, b=1, i click on the button, and b is substracted from 0, so the value are still 0, but the meter is hidden, but if a=1 it don't work.

Im confused. :???:
Update 1:
A=0
1-A=1
A=1

Update 2:
A=1
1-A=0
A=0

Update 3:
A=0
And it goes on, and on, and on...
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Ariex
Posts: 14
Joined: December 23rd, 2010, 1:33 pm
Location: Germany

Re: Some tricks with !SetVariable bang

Post by Ariex »

Lol, yes now it makes sense to me, sorry but i think it was too late for my brain yesterday xD

EDIT: But why it dont works with Hidden ? when Hidden is 0 at start it works, but when a=1, the meter is hidden at start, it dont work, but with Anitalias it works.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Some tricks with !SetVariable bang

Post by smurfier »

Please post your code.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Ariex
Posts: 14
Joined: December 23rd, 2010, 1:33 pm
Location: Germany

Re: Some tricks with !SetVariable bang

Post by Ariex »

I used the config text from Faradey (i have not own config because i wanted to see if it works) and put the variable from Anitalias to Hidden, when A=0, the text is visible at start and the button toggles between visible and unvisible correctly, but when A=1, so that the meter is not visible at start, nothing happens, but with antialias it works correctly, is that maybe a bug in Rainmeter?

[Rainmeter]
Update=1000

[Variables]
A=1

[ExampleMeter]
Meter=String
X=20
Y=0
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=9
FontFace=Arial
Text="Toggling Hide"
AntiAlias=1
Hidden=#A#
DynamicVariables=1

[ButtonToggle]
Meter=String
X=-20r
Y=1r
StringAlign=Left
StringStyle=BOLD
StringEffect=SHADOW
FontColor=255,255,255
FontSize=10
FontFace=Webdings
Text="="
AntiAlias=1
LeftMouseUpAction=!SetVariable A (1-#A#)
DynamicVariables=1
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Some tricks with !SetVariable bang

Post by smurfier »

It's working perfectly fine, it's that -20r that's messing with you. It's moving the string meter to the left out of sight.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Ariex
Posts: 14
Joined: December 23rd, 2010, 1:33 pm
Location: Germany

Re: Some tricks with !SetVariable bang

Post by Ariex »

Oh damn ... thank you :oops: