It is currently April 19th, 2024, 3:55 am

How to use a meter attribute value in a formula?

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to use a meter attribute value in a formula?

Post by balala »

MattNY177 wrote: September 2nd, 2021, 4:41 am I was still just curious about the other part of that question, though... if it's possible to reference another meter's attributes as a variable in a formula? I know you can do it with basic ones like H/W/X/Y such as [MeterName:X] but what about other things like SolidColor, FontColor (string), ImageAlpha (image), etc? Or is the only way to achieve this to store those values in their own variables to be referenced from both the meter and formula?
death.crafter and Active Colors are right. The only possibility is to use those variables as you described. Sorry...
Active Colors wrote: September 2nd, 2021, 9:27 am At the moment the lua script works with Box5 format and returns 5 by using [#INDEX], however it ignores the leading zeros so it is incompatible with Box005 format.
Substitution might help.
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

Re: How to use a meter attribute value in a formula?

Post by MattNY177 »

Sorry in my last reply I made a mistake, I meant to type #CURRENTSECTION# not #CURRENTMEASURE# with regards to referencing parts of a string/variable.

I think I have a good idea of how to make it work now, but if I could throw in a suggestion to the developer for a future update, I think it would be cool to be able to reference part of a string/variable in a formula and convert strings to integers with functions such as LEFT(), RIGHT() and CINT() from C++. For those of us who make skins with lots of similar "indexed" meters, this would allow us to use the #CURRENTSECTION# variable to reference its own index without requiring an external plugin, as long as the meter name contains a numerical value.

Thanks again for all the help it is much appreciated.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to use a meter attribute value in a formula?

Post by balala »

MattNY177 wrote: September 2nd, 2021, 8:58 pm Sorry in my last reply I made a mistake, I meant to type #CURRENTSECTION# not #CURRENTMEASURE# with regards to referencing parts of a string/variable.
Yes, a #CURRENTMEASURE# variable doesn't even exist. :thumbup:
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

Re: How to use a meter attribute value in a formula?

Post by MattNY177 »

SilverAzide wrote: September 1st, 2021, 2:32 pm ActiveColors method is the really fancy way to do it. If you want the old-fashioned low-tech way, in every one of your meters add the expression:

Code: Select all

[Box1]
...
Hidden=(#BoxCount# < 1)

[Box2]
...
Hidden=(#BoxCount# < 2)

;...etc.
The downside to this is you need to edit all 100 meters with different formulas. AC's way is much more auto-magical. :)
After some tinkering I realized this method will not work if you want to toggle visibility of all grouped meters as a triggered action. For example if all meters are hidden by default, then become visible when hovering another meter, you can't selectively apply the (#BoxCount# < X) formula to those meters' Hidden attributes using the !SetOption bang without refreshing the skin.

I am wondering if it is possible to use the Loop measure to accomplish this? Like, when triggered have it loop from 1 to 100, and if #BoxCount# is less than the current value it could assign Hidden=0 to the [Box[&LoopMeasure]] meter?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2603
Joined: March 23rd, 2015, 5:26 pm

Re: How to use a meter attribute value in a formula?

Post by SilverAzide »

MattNY177 wrote: September 4th, 2021, 12:30 am After some tinkering I realized this method will not work if you want to toggle visibility of all grouped meters as a triggered action. For example if all meters are hidden by default, then become visible when hovering another meter, you can't selectively apply the (#BoxCount# < X) formula to those meters' Hidden attributes using the !SetOption bang without refreshing the skin.
Sure it will, you just have to change the formula for the conditions you want. If you have meters that are grouped, then just have a variable that tracks groups and do something like...

Hidden=((#BoxCount# < 1) && (#SomeGroup# = 5))

...Or whatever, it's only limited by your imagination. If you are tweaking these variables on the fly with !SetVariable bangs, then just add DynamicVariables=1 to the meter(s), and it will react as needed on every update.

There is also the Group attribute for a meter, where you can group meters then show and hide them with group bangs, like [!ShowMeterGroup MyGroup]. Grouping can be very powerful, especially when things can belong to multiple groups. You would not use formulas with Hidden in this case, you'd control everything with bangs driven by some event like a mouse action, or an IfCondition in a measure reacting to some state variable. Lots and lots of ways to handle these scenarios, depending on what you are trying to do.
Gadgets Wiki GitHub More Gadgets...
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

Re: How to use a meter attribute value in a formula?

Post by MattNY177 »

SilverAzide wrote: September 4th, 2021, 12:46 am Sure it will, you just have to change the formula for the conditions you want. If you have meters that are grouped, then just have a variable that tracks groups and do something like...

Hidden=((#BoxCount# < 1) && (#SomeGroup# = 5))

...Or whatever, it's only limited by your imagination. If you are tweaking these variables on the fly with !SetVariable bangs, then just add DynamicVariables=1 to the meter(s), and it will react as needed on every update.

There is also the Group attribute for a meter, where you can group meters then show and hide them with group bangs, like [!ShowMeterGroup MyGroup]. Grouping can be very powerful, especially when things can belong to multiple groups. You would not use formulas with Hidden in this case, you'd control everything with bangs driven by some event like a mouse action, or an IfCondition in a measure reacting to some state variable. Lots and lots of ways to handle these scenarios, depending on what you are trying to do.
Yes I understand that, thanks again for your advice. However in this case I was suggesting if you have all 100 boxes in the same group, so you can toggle them to show/hide only the ones that are up to the BoxCount all at once. So for example, if BoxCount=80, when you trigger the toggle it will only unhide those 80 boxes, the other 20 will remain hidden. Then, if you change the BoxCount=40, the same toggle will only show 40 boxes instead of 80, and the other 60 will remain hidden.

It seems like this would require using !SetOption to switch between Hidden=1 and Hidden=(#BoxCount# < X) where X is equal to the individual meter's index. It would also be possible if there was some way to revert those meters back to their original values using !SetOption without refreshing the skin. Otherwise, I would need to manually add and remove each meter from the group whenever I want to change the number of Boxes being toggled.

Does that make sense or am I just misunderstanding something?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2603
Joined: March 23rd, 2015, 5:26 pm

Re: How to use a meter attribute value in a formula?

Post by SilverAzide »

MattNY177 wrote: September 4th, 2021, 4:37 am Yes I understand that, thanks again for your advice. However in this case I was suggesting if you have all 100 boxes in the same group, so you can toggle them to show/hide only the ones that are up to the BoxCount all at once. So for example, if BoxCount=80, when you trigger the toggle it will only unhide those 80 boxes, the other 20 will remain hidden. Then, if you change the BoxCount=40, the same toggle will only show 40 boxes instead of 80, and the other 60 will remain hidden.

It seems like this would require using !SetOption to switch between Hidden=1 and Hidden=(#BoxCount# < X) where X is equal to the individual meter's index. It would also be possible if there was some way to revert those meters back to their original values using !SetOption without refreshing the skin. Otherwise, I would need to manually add and remove each meter from the group whenever I want to change the number of Boxes being toggled.

Does that make sense or am I just misunderstanding something?
Yes, that makes sense. So in this scenario, you are changing the value of #BoxCount# on the fly. For this to dynamically hide/show your meters, you need to add DynamicVariables=1 to every meter. Then, all the meters will hide or show as needed, depending on the expression. Without DynamicVariables, the meters won't re-evaluate the expression and it will have it's original state it had when the skin started. But with it, it is checked on each update. You can force an update and immediately redraw the skin if you need an instant response, otherwise you can wait a second (or whatever your update rate is) for the meters to be updated and redrawn accordingly.

Here's a simple example. (I'm using a Loop measure to twiddle the BoxCount variable just for an example.)

Code: Select all

[Rainmeter]
AccurateText=1
DynamicWindowSize=1

[Variables]
BoxCount=1

[BoxStyle]
FontColor=255,255,255
FontSize=12
SolidColor=0,0,0
Y=20r

[MeasureLoop]
Measure=Loop
StartValue=0
EndValue=3
OnUpdateAction=[!SetVariable BoxCount [MeasureLoop]]

[Box1]
Meter=String
MeterStyle=BoxStyle
Text=Box 1
Y=0
Hidden=(#BoxCount# < 1)
DynamicVariables=1

[Box2]
Meter=String
MeterStyle=BoxStyle
Text=Box 2
Hidden=(#BoxCount# < 2)
DynamicVariables=1

[Box3]
Meter=String
MeterStyle=BoxStyle
Text=Box 3
Hidden=(#BoxCount# < 3)
DynamicVariables=1
I'm using a style to apply similar attributes to all the box meters. You can add the DynamicVariables in the style instead, but I left it out just so you can see.

If you want to use Groups instead, that is a whole different scenario. In that case, you'd use a completely different approach where you'd hide and show items using group bangs (not !SetOption).
Gadgets Wiki GitHub More Gadgets...
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

Re: How to use a meter attribute value in a formula?

Post by MattNY177 »

SilverAzide wrote: September 4th, 2021, 5:12 am Yes, that makes sense. So in this scenario, you are changing the value of #BoxCount# on the fly. For this to dynamically hide/show your meters, you need to add DynamicVariables=1 to every meter. Then, all the meters will hide or show as needed, depending on the expression. Without DynamicVariables, the meters won't re-evaluate the expression and it will have it's original state it had when the skin started. But with it, it is checked on each update. You can force an update and immediately redraw the skin if you need an instant response, otherwise you can wait a second (or whatever your update rate is) for the meters to be updated and redrawn accordingly.
Yes, I have already done that. Your example makes sense, but it does not do what I am trying to accomplish in my previous post, which is to toggle the visibility of the number of boxes specified by #BoxCount# all at once, while leaving the rest of them hidden at all times.

If all 100 boxes are assigned to the same "Boxes" MeterGroup, I can use !SetOptionGroup Boxes Hidden 1 action to quickly hide all box meters. Then if BoxCount=40, I would like the reverse action to instantly show the first 40 boxes while the other 60 remain permanently hidden.

The problem is that !SetOptionGroup Boxes Hidden 0 will always show all 100 boxes even if the original value for each meter was Hidden=(#BoxCount# < X). While your solution does work for static meters, it does not allow for toggling their visibility since I cannot use !SetOptionGroup to change the Hidden attribute back to its original formula because the formula is unique for each meter.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: How to use a meter attribute value in a formula?

Post by death.crafter »

MattNY177 wrote: September 4th, 2021, 6:52 am
Okay.

Case-I:
You have 60 boxes assigned to one group and 40 to another. You want to toggle through them.

Then make 60 boxes have GroupA and the rest GroupB.

Use [!ToggleMeterGroup GroupA][!ToggleMeterGroup GroupB].
Reference

This will hide the meter group which is currently visible and show the group currently hidden.

Case-II:
You have indefinite number of boxes, with the number of boxes you want to show are uncertain, e.g you have 100 boxes and you want to show 30 now, then 35, then 25 etc. Then either use Hidden=(#Count#<BoxIndex), where BoxIndex is the index of the box.

Then it's really your choice if you want to generalize it using [#CURRENTSECTIONINDEX#] and MeterStyle or just assign it to every meter.
from the Realm of Death
User avatar
SilverAzide
Rainmeter Sage
Posts: 2603
Joined: March 23rd, 2015, 5:26 pm

Re: How to use a meter attribute value in a formula?

Post by SilverAzide »

MattNY177 wrote: September 4th, 2021, 6:52 am Yes, I have already done that. Your example makes sense, but it does not do what I am trying to accomplish in my previous post, which is to toggle the visibility of the number of boxes specified by #BoxCount# all at once, while leaving the rest of them hidden at all times.

If all 100 boxes are assigned to the same "Boxes" MeterGroup, I can use !SetOptionGroup Boxes Hidden 1 action to quickly hide all box meters. Then if BoxCount=40, I would like the reverse action to instantly show the first 40 boxes while the other 60 remain permanently hidden.

The problem is that !SetOptionGroup Boxes Hidden 0 will always show all 100 boxes even if the original value for each meter was Hidden=(#BoxCount# < X). While your solution does work for static meters, it does not allow for toggling their visibility since I cannot use !SetOptionGroup to change the Hidden attribute back to its original formula because the formula is unique for each meter.
I'm not sure why you keep wanting to use !SetOption or !SetOptionGroup bangs. What you are doing when using those is blowing away the formula that exists for Hidden. Once you've done that, it's game over, and that's why they stay permanently hidden... you've nuked the formula and it's no longer there. That's why I keep saying to use variables and let the formulas do their thing to control visibility. (And you should be using !HideMeter/!ShowMeter anyway, for clarity at least.)

It's really hard to describe these things in the abstract. You need to post your skin, or at least a functional mockup, to clearly show what you are trying to do.
Gadgets Wiki GitHub More Gadgets...