It is currently April 23rd, 2024, 10:59 pm

help with toggling a variable through a button

Get help with creating, editing & fixing problems with skins
Vilger23
Posts: 4
Joined: December 30th, 2019, 9:56 pm

help with toggling a variable through a button

Post by Vilger23 »

I want to create a button that toggles all my icons(rainmeter skins) to when clicked open up "Rick Ashleys - never going to give you up".
My variable "RickRoll" doesn't even change from 0 to 1 when I click the button, like I would expect it to do. Is there anyone that can figure out what's wrong with my code???
Thankful for any insight.

Code for the "button"

Code: Select all

 
 [RainMeter]
 Update = 1000
 AccurateText = 1
 SolidColor=0,0,0,1
 OnRefreshAction=[!ZPos 1]
 LeftMouseUpAction= !Execute[!UnpauseMeasureGroup "RickRolled"][!Update "#CURRENTCONFIG#"]

[variables]
 @include=#@#RickRollVar.ini

[Metadata]
 Name=RickRoll
 Author=Vilger23
 Information= Something Different
 License=NaN
 Version=1.0


[InvisibleButton]
 Meter=Shape
 Shape = Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 0
 MouseOverAction=[!SetOption "#CURRENTSECTION#" "Shape" "Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 1 | Stroke Color #white#"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
 MouseLeaveAction=[!SetOption "#CURRENTSECTION#" "Shape" "Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 0"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
 
[SetRickRoll]
Measure=CalC
Formal=#RickRoll#
group=RickRolled
paused=1
IfBelowValue= 1
IfValueAction=!Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "1" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
IfAboveValue = 0
IfValueAction = !Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "0" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
DynamicVariables=1

Code for the variables:

Code: Select all

[variables]
 RickRoll = 0

Code for the Icons (In this case youtube):

Code: Select all

[variables]
@include = "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"

[youtube]
Meter=Image
ImageName=#@#Images\youtube.png
H=90

[SetRickRoll]
 Measure=CalC
 Formula=#RickRoll#
 IfAboveValue=0
 IfAboveAction= !Execute["http://youtube.com/"][!PauseMeasureGoup "RickRolled"][!Refresh #CURRENTCONFIG#]
 IfBelowValue=1
 IfAboveAction= !Execute["https://www.youtube.com/watch?v=dQw4w9WgXcQ"][!PauseMeasureGoup "RickRolled"][!Refresh #CURRENTCONFIG#]
 Group=RickRolled
 Paused=1

[Rainmeter]
Update=1000
LeftMouseUpAction=!Execute[!UnpauseMeasureGroup "RickRolled"][!Refresh #CURRENTCONFIG#]

[Metadata]
Name=youtube
Author=APIUM
Information=
License=
Version=
Vilger23
Posts: 4
Joined: December 30th, 2019, 9:56 pm

Re: help with toggling a variable through a button

Post by Vilger23 »

I noticed it said formal instead of formula in the measure but after that fix it still doesn't work
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: help with toggling a variable through a button

Post by Mor3bane »

Hi. you are using several depreciated Bangs.

the !Rainmeter preceeding your !WriteKeyValue is no longer needed, also not needed is the !Execute check the Rainmeter manual for anything else that may have changed. https://docs.rainmeter.net/manual/

You should also download the latest Rainmeter which is 4.3 or the beta of 4.4 here: https://www.rainmeter.net/
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: help with toggling a variable through a button

Post by Mor3bane »

Code: Select all

IfBelowValue= 1
IfValueAction=!Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "1" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
IfAboveValue = 0
IfValueAction = !Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "0" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
The way your IfValue is also not used: https://docs.rainmeter.net/manual/measures/general-options/ifactions/
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
Vilger23
Posts: 4
Joined: December 30th, 2019, 9:56 pm

Re: help with toggling a variable through a button

Post by Vilger23 »

Mor3bane wrote: December 30th, 2019, 11:16 pm

Code: Select all

IfBelowValue= 1
IfValueAction=!Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "1" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
IfAboveValue = 0
IfValueAction = !Execute[!RainmeterWriteKeyValue "variables" "RickRoll" "0" "C:\Rainmeter\Skins\RickRoll\@Resources\RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
The way your IfValue is also not used: https://docs.rainmeter.net/manual/measures/general-options/ifactions/
Thanks, I will try to see if my code will work after this^^
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5406
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: help with toggling a variable through a button

Post by eclectic-tech »

Vilger23 wrote: December 30th, 2019, 11:22 pm Thanks, I will try to see if my code will work after this^^
I would simplify the code (less chances for errors) to this:

Code: Select all

 
 [RainMeter]
 Update = 1000
 AccurateText = 1
 SolidColor=0,0,0,1
 OnRefreshAction=[!ZPos 1]
 
[variables]
 @include=#@#RickRollVar.ini

[Metadata]
 Name=RickRoll
 Author=Vilger23
 Information= Something Different
 License=NaN
 Version=1.0


[InvisibleButton]
 Meter=Shape
 Shape = Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 0
 MouseOverAction=[!SetOption "#CURRENTSECTION#" "Shape" "Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 1 | Stroke Color #white#"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
 MouseLeaveAction=[!SetOption "#CURRENTSECTION#" "Shape" "Rectangle 0,30,30,30,30 | Fill Color 255,0,0,1 | StrokeWidth 0"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
 
 LeftMouseUpAction=[!WriteKeyValue "variables" "RickRoll" "(1-#RickRoll#)" "#@#RickRollVar.ini"][!Refresh "#CURRENTCONFIG#"][!PauseMeasureGroup "RickRolled"]
 
I moved the LeftMouseUpAction to the Shape meter and changed it's action to a formula that will toggle the "RickRoll" variable value between 0 and 1 on each click. This let's you remove the last measure and eliminates the need to use any condition actions; everything is done by using a formula.

Notes:
I would be inclined to use #@# to refer to your "@Resources" folder instead of using full-paths.
I would also suggest renaming the include file to "RickRollVar.inc" so it does NOT appear as a "functional skin" in the Rainmeter skin list.

Hope this helps :Whistle
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: help with toggling a variable through a button

Post by balala »

Vilger23 wrote: December 30th, 2019, 10:25 pm I want to create a button that toggles all my icons(rainmeter skins) to when clicked open up "Rick Ashleys - never going to give you up".
Besides eclectic-tech's code, let's see if I understood exactly what you want. If I'm not wrong you'd like a meter to click on to load the skins if they are not loaded, or unload them if they are loaded. Is this correct?