It is currently September 8th, 2024, 12:11 am

Nested Conditions + Formulas

Get help with creating, editing & fixing problems with skins
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Nested Conditions + Formulas

Post by sl23 »

Just trying out something to see if it works, but I think I need an alternative way of doing it.

I understand that you can use number values only, but does that mean you can't change the values of a colour due to the commas and multiple number values?

eg:
DiskNorm=255,255,255,180
FontColor=(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskNorm# : 0)
The zero at the end of the condition will be where I add the other conditions if I can.

Thanks :thumbup:

EDIT: Assuming it was possible, likely not, but let's say it is, would this be the correct syntax?

Code: Select all

FontColor=(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskNorm# : ((((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskRead# : 0)||(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskWrite# : 0)||(((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskBoth# : 0)))

57686174 77696C6C 6265 77696C6C 6265
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

I'm also trying to figure out why this isn't working:

Code: Select all

Hidden=([#m[#CURRENTSECTION]]=1 ? [UL:W]+2 : [UL:W]#BarW#+2)
Is it incorrect syntax?
The Variables are correct as I'm using them elsewhere.
The 'UL' will be replaced with #CURRENTSECTION# once I know this is correct.
57686174 77696C6C 6265 77696C6C 6265
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Nested Conditions + Formulas

Post by balala »

sl23 wrote: July 18th, 2024, 12:11 pm eg:
DiskNorm=255,255,255,180
FontColor=(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskNorm# : 0)
The zero at the end of the condition will be where I add the other conditions if I can.
There are more issues with the posted formula:
  • A mathematical formula, used anywhere (in a Formula option of a Calc measure, in an IfCondition or into an any option, as you did) has to be ENTIRELY NUMERIC. Your DiskNorm variable (in fact any variable storing a color) is a string, even if it contains four numbers (besides the numbers, it has three commas, which are not allowed into numbers).
  • Besides this, even if the formula wouldn't return a string but a number and it could work by this, the formula itself has a condition check which doesn't make sense. This is what am I talking about: FontColor=(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskNorm# : 0). The red colored =0 doesn't match in the mathematical formula.
  • Finally, the numerical values returned by measures can be used simply only in Formula options of Calc measures and in IfConditions. Outside of these options you have to use them as section variables (this requires to add the DynamicVariables=1 option to the meter - or measure, why not? - where you want to use it). So not taking into account the previously mentioned issues, the above FontColor should contain those brackets, delimiting the section variables: FontColor=((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0))=0 ? #DiskNorm# : 0) and the meter should contain the DynamicVariables=1 option.
  • One more thing you definitely should take care of: the name of the meter in which you want to use this FontColor option should be the one you have used in the names of the mXXXDiskRead and mXXXDiskWrite measures (I assume it should be for instance C, to get the mCDiskRead and mCDiskWrite measure names).
Taking all this into account, a form of the above FontColor option which could work looks this way: FontColor=((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0)) ? 255 : 0),((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0)) ? 255 : 0),((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0)) ? 255 : 0),((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0)) ? 180 : 0). See that there are four different sections, each of them returning one elemnet of the color code. These elements are numbers and can be used into mathematical formulas.
Let's stop here for first. I don't go further with the question posted into your second post. I think for first we should fix the first issue, only then we should go further.
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

Thanks balala, that was a great help in understanding why it wasn't working and how to get it to work, much appreciated. :thumbup:

A quick comment on your points:
  • I did think that the commas were the problem here, hence my comment about that :)
  • On first reading, I was adamant this was correct, until I read the original code! lol Thanks for that.
  • This is one of the issues I have, knowing when and where but mainly WHY I need to use brackets.
  • This one I know well and am fully aware of it, thanks.
I really was just trying to learn some more about formulas and how they work, always loved maths at school :D
Never had a reason to use it my whole life though! :(


That final code seems overkill for using where I planned to, given there will be another twelve for Disk Read and Write variations! O.O
Think I'll leave this as is. My aim was learning to use formulas to try condense things, least if that was a possibility, but I suppose it's not in all cases.

This is my working code at present, apart from the FontColor part obviously:

Code: Select all

[sAllText]
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=CenterCenter
FontSize=9
FontColor=#White#
FontColor=((([m#CURRENTSECTION#DiskRead]=0)&&([m#CURRENTSECTION#DiskWrite]=0)) ? #DiskNorm# : ((((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskRead# : 0)||(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskWrite# : 0)||(((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskBoth# : 0)))
;FontColor=(((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite=0))=0 ? #DiskRead# : 0)
;FontColor=(((m#CURRENTSECTION#DiskRead=0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskWrite# : 0)
;FontColor=(((m#CURRENTSECTION#DiskRead>0)&&(m#CURRENTSECTION#DiskWrite>0))=0 ? #DiskBoth# : 0)
SolidColor=#Bg#
AntiAlias=1
DynamicVariables=1
MeasureName=m#CURRENTSECTION#Label
MeasureName2=m#CURRENTSECTION#Used
MeasureName3=m#CURRENTSECTION#Free
MeasureName4=m#CURRENTSECTION#Total
Text=[#Disk[#CURRENTSECTION]]
Hidden=([m#CURRENTSECTION#Total:]=0 ? 1 : 0)
ToolTipTitle=%1: %2B
ToolTipText=%3 / %4
Group=[#Disk[#CURRENTSECTION]]
LeftMouseUpAction=[#XY# /path="[#Disk[#CURRENTSECTION]]:\"]
MiddleMouseUpAction=["#@#\USBDiskEjector\USB_Disk_Eject.exe """/SHOWEJECT /REMOVELETTER "[#Disk[#CURRENTSECTION]]:\"""""]
X=([m#CURRENTSECTION#Total:]=0 ? 0 : #BarW#+2)r
Y=r
W=#BarW#
This is a Text Style that all drive letters use via MeterStyle=sAllText.
57686174 77696C6C 6265 77696C6C 6265
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Nested Conditions + Formulas

Post by Yincognito »

sl23 wrote: July 18th, 2024, 9:14 pm That final code seems overkill for using where I planned to, given there will be another twelve for Disk Read and Write variations! O.O
To simplify and make things more compact, why not doing something like (basic syntax used below for simplicity):

Code: Select all

Color0=...
Color1=...
Color2=...
...
FontColorIndex=([SomeMeasure]=0?1:0)
FontColor=[#Color[#FontColorIndex]]
In other words, instead of trying to set the color directly in the conditional, set its index (assuming that the color variables are defined using indexes, obviously), and then set the color based on that index, via the nested syntax.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

Thanks, but I gave up on that! Starting to hurt my brain! lol
The second post is still something I would like to get sorted though.

And also, I'm trying to sort another skin with Shapes. Disk skin showing a simple line rather than a bar, but everything I try fails in one way or another. I tried Bars, but the line wouldn't show in the correct place. Now I'm using separate Shapes for each disk, despite it working perfectly fine, bit strange on the insert/removal as other drives hide during that process, but getting an errors on every update saying the formula is wrong for every drive unplugged! :x

This is driving me bonkers!
DiskCode:

Code: Select all

[sBar]
Shape=Rectangle 0, 0, #BarW#, -#BarH# | StrokeWidth 0 | Fill Color #Bg#
DynamicVariables=1
Hidden=([m#CURRENTSECTION#:]=0 ? 1 : 0)
X=([m#CURRENTSECTION#:]=0 ? 0 : 2)R
Y=#BarH#

[1Used]
Meter=Shape
MeterStyle=sBar
Shape2=Rectangle 0, ([m#CURRENTSECTION#:]/[m1Total:]*-#BarH#), #BarW#, 2 | StrokeWidth 0 | Fill Color [#C[#CURRENTSECTION]]
X=0
Error: Formula: Division by 0: (0/0*-46)
Last edited by sl23 on July 19th, 2024, 11:08 am, edited 2 times in total.
57686174 77696C6C 6265 77696C6C 6265
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Nested Conditions + Formulas

Post by balala »

sl23 wrote: July 18th, 2024, 9:14 pm
  • I did think that the commas were the problem here, hence my comment about that :)
They are.
sl23 wrote: July 18th, 2024, 9:14 pm
  • On first reading, I was adamant this was correct, until I read the original code! lol Thanks for that.
:thumbup:
sl23 wrote: July 18th, 2024, 9:14 pm
  • This is one of the issues I have, knowing when and where but mainly WHY I need to use brackets.
As said the brackets are not needed into the Formula option of a Calc measure and in IfConditions. Use them everywhere else and don't forget about the dynamic variables.
sl23 wrote: July 18th, 2024, 9:14 pm
  • This one I know well and am fully aware of it, thanks.
Just added it, to make sure you know about it.
sl23 wrote: July 18th, 2024, 9:14 pm This is my working code at present, apart from the FontColor part obviously:
And does it works well? I hope it does.
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

Thanks for your help. :thumbup:

Yes I made one version that works well, but trying to make a second version that doesn't seem to want to work at all, see post above. :(
57686174 77696C6C 6265 77696C6C 6265
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

Can I use the hidden status in the formula like this:
([#CURRENTSECTION#:Hidden]=1 ? 0 : ([m#CURRENTSECTION#:]/[m1Total:]*-#BarH#))
57686174 77696C6C 6265 77696C6C 6265
User avatar
sl23
Posts: 1600
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Nested Conditions + Formulas

Post by sl23 »

Yincognito wrote: July 19th, 2024, 10:00 am To simplify and make things more compact, why not doing something like (basic syntax used below for simplicity):

Code: Select all

Color0=...
Color1=...
Color2=...
...
FontColorIndex=([SomeMeasure]=0?1:0)
FontColor=[#Color[#FontColorIndex]]
In other words, instead of trying to set the color directly in the conditional, set its index (assuming that the color variables are defined using indexes, obviously), and then set the color based on that index, via the nested syntax.
Actually, that's pretty neat and may come in handy with other stuff! Thanks. :thumbup:
57686174 77696C6C 6265 77696C6C 6265