It is currently January 26th, 2021, 10:20 pm

Floating Variable For Image State On/Off But with More than One Button

Help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 233
Joined: September 7th, 2020, 2:24 pm

Floating Variable For Image State On/Off But with More than One Button

Post by CodeCode »

Hello, I have an image toggle that goes between Hidden=0 or Hidden=1. It is managed by a Variable "aState", and it works fine. Also for 12 total buttons, the toggle works.

The hitch is that once an image is toggled hidden or not hidden, clicking another of the 12 buttons continues to toggle the same Variable aState, Hidden=1 or Hidden=0. The means even though separate images are being toggled, the same variable state persists between buttons, so if ButtonOne is Hidden then, ButtonTwo chooses to be not hidden, etc.

So I am trying to create a floating Toggle Variable that allows each button to start from a fixed state of Hidden = 0. So When Each button is clicked for the first time the image will be shown - toggled to Hidden=1 if clicked again, on and on for each of the 12 buttons.

Here is the code parts:

Code: Select all

[Variables]
ButtonOneImage=""swtor.png""
ButtonTwoImage=""skyrim.png""
aState=0

[ContainerA]
Meter=Shape
Shape=Rectangle 37,36,208,207,103
DynamicVariables=1

[ImageA]
Meter=Image
ImageName=#ImageNameA#
Container=ContainerA
AntiAlias=1
X=34
Y=34
W=213
H=211
UseExifOrientation=1
PreserveAspectRatio=1
DynamicVariables=1
Group=buttons
Hidden=#aState#

[Button1]
Meter=Image
ImageName=MyButtonFile.png
X=238
Y=144
W=36
H=35
Antialias=1
LeftMouseUpAction=[!WriteKeyValue Variables aState "(1-#aState#)"][!SetVariable "aState" "(1-#aState#)"][!SetOption ImageA Hidden "(1-#aState#)"][!UpdateMeter ImageA][!WriteKeyValue "Variables" "ImageNameA" #ButtonOneImage#][!SetOption "Variables" "ImageNameA" ""#ButtonOneImage#""][!Update]

[Button2]
Meter=Image
ImageName=MyButtonFile.png
X=219
Y=194
W=36
H=35
Antialias=1
LeftMouseUpAction=[!WriteKeyValue Variables aState "(1-#aState#)"][!SetVariable "aState" "(1-#aState#)"][!SetOption ImageA Hidden "(1-#aState#)"][!UpdateMeter ImageA][!WriteKeyValue "Variables" "ImageNameA" #ButtonTwoImage#][!SetOption "Variables" "ImageNameA" ""#ButtonTwoImage#""][!Update]
I hope that is enough of an example of what I am working with, and trying to achieve.

Thanks for any examples or suggestions.
swtor.png
skyrim.png
MyButtonFile.png
You do not have the required permissions to view the files attached to this post.
Can't fix it if it ain't broke - unless it is in code.
User avatar
balala
Rainmeter Sage
Posts: 12112
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Floating Variable For Image State On/Off But with More than One Button

Post by balala »

CodeCode wrote: January 2nd, 2021, 5:04 am The hitch is that once an image is toggled hidden or not hidden, clicking another of the 12 buttons continues to toggle the same Variable aState, Hidden=1 or Hidden=0. The means even though separate images are being toggled, the same variable state persists between buttons, so if ButtonOne is Hidden then, ButtonTwo chooses to be not hidden, etc.

So I am trying to create a floating Toggle Variable that allows each button to start from a fixed state of Hidden = 0. So When Each button is clicked for the first time the image will be shown - toggled to Hidden=1 if clicked again, on and on for each of the 12 buttons.
Let's summarize a little bit, because I'm not sure I undertood well what you want: are there more [ImageX] meters (with the appropriate [ContainerX] containers), each ones visibility controled by the aState variable? Am I right? If I am, I suppose you should use different variables to set the visibility of each of those meters.
If I am right, I'm gonna post an example of code, but first please confirm (or deny).
User avatar
CodeCode
Posts: 233
Joined: September 7th, 2020, 2:24 pm

Re: Floating Variable For Image State On/Off But with More than One Button

Post by CodeCode »

balala wrote: January 2nd, 2021, 11:02 am Let's summarize a little bit, because I'm not sure I undertood well what you want: are there more [ImageX] meters (with the appropriate [ContainerX] containers), each ones visibility controled by the aState variable? Am I right? If I am, I suppose you should use different variables to set the visibility of each of those meters.
If I am right, I'm gonna post an example of code, but first please confirm (or deny).
No that is not what I meant to say. However, I think I am trying to do this the hard way. Let me get back to experimenting before you post anything.

I'll work on the issue on my own for now.

Thanks.
Can't fix it if it ain't broke - unless it is in code.
User avatar
balala
Rainmeter Sage
Posts: 12112
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Floating Variable For Image State On/Off But with More than One Button

Post by balala »

CodeCode wrote: January 2nd, 2021, 9:39 pm I'll work on the issue on my own for now.
Ok, as you wish.
User avatar
CodeCode
Posts: 233
Joined: September 7th, 2020, 2:24 pm

Re: Floating Variable For Image State On/Off But with More than One Button

Post by CodeCode »

Alrighty now.
I was trying to avoid repetitious code. Seems there was no other way.

I have it working now. Sorry, I wont post the code, it is very repetitious and a bit confusing, since there are 12 variations of the same code that in turn each have over 30 bangs each again.

Thanks balala for chiming in. But this one was just having that repetitious code, and getting each variation correct. My current testing seems to check out in the 'working' order.
Can't fix it if it ain't broke - unless it is in code.
User avatar
CodeCode
Posts: 233
Joined: September 7th, 2020, 2:24 pm

Re: Floating Variable For Image State On/Off But with More than One Button

Post by CodeCode »

Ok, this is one of the 12 buttons' code:

Code: Select all


[ButtonA]
Meter=Image
ImageName=#@##MyButtonFile#
X=10
Y=87
W=36
H=35
LeftMouseUpAction=[!WriteKeyValue Variables StateA "(1-#StateA#)"][!SetVariable "StateA" "(1-#StateA#)"][!SetOption ImageA Hidden "(1-#StateA#)"][!SetOption Variables State2 "1"][!SetOption Variables State3 "1"][!SetOption Variables State5 "1"][!SetOption Variables State6 "1"][!SetOption Variables State7 "1"][!SetOption Variables State1 "1"][!SetOption Variables StateB "1"][!SetOption Variables StateC "1"][!SetOption Variables StateD "1"][!SetOption Variables StateE "1"][!SetOption Variables StateF "1"][!WriteKeyValue Variables State2 "1"][!WriteKeyValue Variables State3 "1"][!WriteKeyValue Variables State5 "1"][!WriteKeyValue Variables State6 "1"][!WriteKeyValue Variables State7 "1"][!WriteKeyValue Variables State1 "1"][!WriteKeyValue Variables StateB "1"][!WriteKeyValue Variables StateC "1"][!WriteKeyValue Variables StateD "1"][!WriteKeyValue Variables StateE "1"][!WriteKeyValue Variables StateF "1"][!UpdateMeter ImageA][!WriteKeyValue "Variables" "bState" #ButtonAPersistentHoverText#][!SetOption "Variables" "bState" ""#ButtonAPersistentHoverText#""][!WriteKeyValue "Variables" "ImageNameA" #ButtonAImage#][!WriteKeyValue "Variables" "ImageNameA" ""#ButtonAImage#""][!SetOption "Variables" "ImageNameA" ""#ButtonAImage#""][!WriteKeyValue "Variables" "LaunchA" #ButtonALaunch#][!SetOption "Variables" "LaunchA" ""#ButtonALaunch#""][!RefreshGroup PassMan][!WriteKeyValue Variables ClipA #ButtonASetClip#][!SetOption Variables ClipA #ButtonASetClip#][!SetClip #ClipA#][!Update]
MouseOverAction=[!SetOption "MeterLowerButtonHover" "Text" ""#PersistentText#""][!WriteKeyValue "ConfirmClickText" "Text" ""#ButtonAPersistentHoverText#""][!SetOption "ConfirmClickText" "Text" ""#ButtonAPersistentHoverText#""][!SetOption "Clicky8" "Hidden" "0"][!Redraw]
MouseLeaveAction=[!SetOption "MeterLowerButtonHover" "Text" """ """][!SetOption "Clicky8" "Hidden" "1"][!Redraw]
DynamicVariables=1
Hidden=#State#
Group=one
Can't fix it if it ain't broke - unless it is in code.
User avatar
Alex88
Posts: 70
Joined: July 18th, 2020, 1:23 am
Location: California

Re: Floating Variable For Image State On/Off But with More than One Button

Post by Alex88 »

I'm not 100% on the specifics of what you're going for, but maybe try to use meter groups in conjunction with !HideMeterGroup. So if you assign Group=AllButtons to each button, you could then use [!HideMeterGroup AllButtons][!ShowMeter Button1]. That will hide all the button meters at once and bring forward only the one you want afterwards, and alleviates having to use variables. You could otherwise use !SetOptionGroup as well.
User avatar
balala
Rainmeter Sage
Posts: 12112
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Floating Variable For Image State On/Off But with More than One Button

Post by balala »

CodeCode wrote: January 2nd, 2021, 10:40 pm I was trying to avoid repetitious code.
Not possible in a Rainmeter code, this being the case in each (or almost each) such code. Rainmeter is not a programming language and as such, you have to repeat what you have to repeat, unlike in a programming language.
User avatar
balala
Rainmeter Sage
Posts: 12112
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Floating Variable For Image State On/Off But with More than One Button

Post by balala »

CodeCode wrote: January 2nd, 2021, 10:54 pm Ok, this is one of the 12 buttons' code:
And I suppose the [ButtonB] meter is working with StateB variable and so on, right?
User avatar
CodeCode
Posts: 233
Joined: September 7th, 2020, 2:24 pm

Re: Floating Variable For Image State On/Off But with More than One Button

Post by CodeCode »

balala wrote: January 3rd, 2021, 9:27 am And I suppose the [ButtonB] meter is working with StateB variable and so on, right?
Yep.
Can't fix it if it ain't broke - unless it is in code.