It is currently April 23rd, 2024, 9:57 pm

Toggling a variable in a Shape meter

Get help with creating, editing & fixing problems with skins
User avatar
Lieuallen
Posts: 50
Joined: June 8th, 2020, 11:56 pm
Location: Chapel Hill, NC (US)

Toggling a variable in a Shape meter

Post by Lieuallen »

There is something very obvious that I am missing, but I've been staring at this for half an hour now!

I have an extremely simple skin. I just want to display a small image (hidden at first), and toggle it on and off with a mouse click. I've drawn a small shape, and I figured I'd use that as the toggle button. But, my code below never changes the value of #HideImage#.

Please show me the error of my ways!

Code: Select all

[Rainmeter]
Update=-1

HideImage=1

; ---------------------------------- Image
[ImageW]
Meter=Image
ImageName=#CurrentPath#ImageW.png
X=0
Y=0
Hidden=#HideImage#

[MM&I Logo]
Meter=Shape
LeftMouseUpAction=[!SetVariable HideImage "(1-#HideImage#)"][!Refresh]
DynamicVariables=1
X=1
Y=85
Shape=Path MMIPath | StrokeWidth 1 | Stroke Color 255,0,0,128 | Fill Color 255,0,0,255
MMIPath=4,0 | LineTo 12,0 | LineTo 4,14 | LineTo 0,7 | LineTo 16,7 | LineTo 12,14 | ClosePath 1
Always sure, sometimes right.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Toggling a variable in a Shape meter

Post by jsmorley »

Lieuallen wrote: August 3rd, 2020, 4:48 pm There is something very obvious that I am missing, but I've been staring at this for half an hour now!

I have an extremely simple skin. I just want to display a small image (hidden at first), and toggle it on and off with a mouse click. I've drawn a small shape, and I figured I'd use that as the toggle button. But, my code below never changes the value of #HideImage#.

Please show me the error of my ways!

Code: Select all

[Rainmeter]
Update=-1

HideImage=1

; ---------------------------------- Image
[ImageW]
Meter=Image
ImageName=#CurrentPath#ImageW.png
X=0
Y=0
Hidden=#HideImage#

[MM&I Logo]
Meter=Shape
LeftMouseUpAction=[!SetVariable HideImage "(1-#HideImage#)"][!Refresh]
DynamicVariables=1
X=1
Y=85
Shape=Path MMIPath | StrokeWidth 1 | Stroke Color 255,0,0,128 | Fill Color 255,0,0,255
MMIPath=4,0 | LineTo 12,0 | LineTo 4,14 | LineTo 0,7 | LineTo 16,7 | LineTo 12,14 | ClosePath 1
You don't want to [!Refresh], that reloads the skin and starts over, and #HideImage# is back to "1". You can just [!UpdateMeter *][!Redraw] or even just [!Update].

If you really need to do a [!Refresh] there for some reason, you are going to want to "write" the value of #HideImage# to the file, so it is the "toggled" state when the skin is refreshed.

[!WriteKeyValue Variables HideImage "(1-#HideImage#)"][!Refresh]
User avatar
Lieuallen
Posts: 50
Joined: June 8th, 2020, 11:56 pm
Location: Chapel Hill, NC (US)

Re: Toggling a variable in a Shape meter

Post by Lieuallen »

Removing the [!Refresh] does (of course) let the variable toggle. I'm pretty new, but geez -- I should have realized that!

The other little boo-boo was not including DynamicVariables=1 in the Image's meter. So even though the variable was changing, the meter wasn't using the new value!

Anyway, all's well that ends well! Thanks for the help!
Last edited by Lieuallen on August 3rd, 2020, 5:32 pm, edited 1 time in total.
Always sure, sometimes right.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Toggling a variable in a Shape meter

Post by jsmorley »

Lieuallen wrote: August 3rd, 2020, 5:22 pm I originally had a [!Redraw], but when that didn't work, I switched it to [!Refresh]. But I do now see that that won't work, since it restarts the entire skin, resetting #HideImage# to one.

Unfortunately, neither [!Update] nor [!UpdateMeter *][!Redraw] works for me.

What I'm seeing is through the Rainmeter Log. In this skin, I see HideImage listed as the only variable. It is 1, and no matter how many times I click the shape, it stays 1. So it seems my SetVariable bang isn't working, or isn't triggered.

I should note that my cursor does change to the "hand" when I'm hovering over the shape, so it sure seems like it should work! But, as I said, HideImage stays set at 1 no matter what I do. If I define HideImage as 0 in the initital [Variables] section, then it instead stays stuck at zero. I can't seem to toggle it....

I've read the documentation, and it discusses that you must click on a "solid" part of a shape for the mouse actions to trigger. My shape is really small, but I'm pretty sure that I'm clicking on it (evidenced by the "hand" cursor).
Ah, You don't have HideImage defined in a [Variables] section of your skin. So it's not a variable.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Toggling a variable in a Shape meter

Post by jsmorley »

Oh, and you need to add DynamicVariables=1 to [ImageW]

That will cause it to work, although you won't see the change in the Log. This is because the skin is never updating, so the Log is not updated.
User avatar
Lieuallen
Posts: 50
Joined: June 8th, 2020, 11:56 pm
Location: Chapel Hill, NC (US)

Re: Toggling a variable in a Shape meter

Post by Lieuallen »

Kinda embarrassing -- I actually DO have the [Variables] section. But when I cut out the [Metadata] section for brevity, I accidentally deleted that line as well!

Anyway, as I said, I've got it working now. Thanks!!
Always sure, sometimes right.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Toggling a variable in a Shape meter

Post by jsmorley »

Lieuallen wrote: August 3rd, 2020, 5:33 pm Kinda embarrassing -- I actually DO have the [Variables] section. But when I cut out the [Metadata] section for brevity, I accidentally deleted that line as well!

Anyway, as I said, I've got it working now. Thanks!!
Glad to help.