It is currently January 22nd, 2022, 6:34 am

[solved] help to simplify a bunch of IfCondition

Help with creating, editing & fixing problems with skins
User avatar
carlitosbahia
Posts: 12
Joined: December 30th, 2021, 10:32 pm

[solved] help to simplify a bunch of IfCondition

Post by carlitosbahia »

hi, i have this simple skin where one of the things i show is the day of the month , 1 to 31 with an inline format , next to the previous and next day in "dimmed format"

Text=#NumeroMenos# #Numero# #NumeroMas#
"2 3 4" in this example for today

Code: Select all

[Number]
Meter=String
FontFace=#FontName#
FontColor=#FontDimmedColor#
FontSize=#FontMainSize#
Text=#NumeroMenos# #Numero# #NumeroMas#
InlineSetting=Color | #FontFullColor#
Antialias=1
StringAlign=Center
X=215
Y=0R
Image
ignore the spanish ( code is also half english half spanish ;) )


as you can see in the screenshot it is working as intended, no problem there

the problem starts in the IfConditions i use to set the day before, today and tomorrow and set the inline format for today
they work, but they are too many ( 31 of them , plus 31 action lines ... ) and i would like to "optimize" it , make that part smaller

Code: Select all

[MeasureNumber]
Measure=Time
Format=%#d
IfCondition=MeasureNumber = 1
IfTrueAction=[!SetOption Number InlinePattern " 1 "]|[!SetVariable NumeroMenos 31]|[!SetVariable Numero 1]|[!SetVariable NumeroMas 2]
IfCondition2=MeasureNumber = 2
IfTrueAction2=[!SetOption Number InlinePattern " 2 "]|[!SetVariable NumeroMenos 1]|[!SetVariable Numero 2]|[!SetVariable NumeroMas 3]

....

up to ( deleted for simplicity for the forum )

...

IfCondition30=MeasureNumber = 30
IfTrueAction30=[!SetOption Number InlinePattern " 30 "]|[!SetVariable NumeroMenos 29]|[!SetVariable Numero 30]|[!SetVariable NumeroMas 31]
IfCondition31=MeasureNumber = 31
IfTrueAction31=[!SetOption Number InlinePattern " 31 "]|[!SetVariable NumeroMenos 30]|[!SetVariable Numero 31]|[!SetVariable NumeroMas 1]
so, since the result of MeasureNumber is a number i thought i could just use that as a variable , substract 1 , add 1 , and do all that with 3 conditions only (1st , 2nd to 30th , 31th )

something like

Code: Select all

[MeasureNumber]
Measure=Time
Format=%#d
IfCondition=MeasureNumber = 1
IfTrueAction=[!SetOption Number InlinePattern " 1 "]|[!SetVariable NumeroMenos 31]|[!SetVariable Numero 1]|[!SetVariable NumeroMas 2]
IfCondition2= ( MeasureNumber >1 )&&( MeasureNumber <31 )
IfTrueAction2=[!SetOption Number InlinePattern MeasureNumber]|[!SetVariable NumeroMenos MeasureNumber-1]|[!SetVariable Numero MeasureNumber]|[!SetVariable NumeroMas MeasureNumber+1]
IfCondition3=MeasureNumber = 31
IfTrueAction3=[!SetOption Number InlinePattern " 31 "]|[!SetVariable NumeroMenos 30]|[!SetVariable Numero 31]|[!SetVariable NumeroMas 1]
IfConditionMode=1
note that i am using for example " 1 " because want to add the spaces so 1 does not match also the 1 in 10 ... 19 , 21 , 31

what happens with that now ?
Image

tried also adding the ()
(MeasureNumber+1)

but that only added the () to the text it shows, it does not calculate it

my idea was doing something similar to the day of the week and month, but if i can't make it with numbers ( should be easier ? ) , then not sure about the strings , lol

how would you do this?
any way to have less than 64 lnes just for that part would be nice
Last edited by carlitosbahia on January 4th, 2022, 10:59 pm, edited 2 times in total.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4581
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: help to simplify a bunch of IfCondition

Post by eclectic-tech »

Instead of using the date number to test, use the TimeStamp of today, subtract 1 day of seconds (86400) for yesterday, and add 86400 seconds for tomorrow.

Read more about working with TimeStamps here...

Sample code showing values for yesterday, today, and tomorrow.

Code: Select all

; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#

; ========= Measures ==========
[MeasureToday]
Measure=Time
Format=%#c
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes

[MeasureYesterday]
Measure=Time
Format=%#c
TimeStamp=([MeasureToday:TimeStamp]-86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


[MeasureTomorrow]
Measure=Time
Format=%#c
TimeStamp=([MeasureToday:TimeStamp]+86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


; ========= Meter Styles ==========



; ========= Meters ==========
[MeterYesterday]
Meter=String
MeasureName=MeasureYesterday
X=([MeterTomorrow:W])
StringAlign=Right
Text="    Yesterday was: %1"
SolidColor=0,0,0,1
DynamicVariables=1

[MeterToday]
Meter=String
MeasureName=MeasureToday
X=([MeterTomorrow:W])
StringAlign=Right
Text="              Today is: %1"
Y=R
SolidColor=0,0,0,1
DynamicVariables=1

[MeterTomorrow]
Meter=String
MeasureName=MeasureTomorrow
X=([MeterTomorrow:W])
StringAlign=Right
Text=Tomorrow will be: %1
Y=R
SolidColor=0,0,0,1
DynamicVariables=1
3days.png
By changing the Time measure Format option you can get any date/time details you want as the values of the measures for today, yesterday, or tomorrow.
You do not have the required permissions to view the files attached to this post.
User avatar
carlitosbahia
Posts: 12
Joined: December 30th, 2021, 10:32 pm

Re: help to simplify a bunch of IfCondition

Post by carlitosbahia »

yeah, that works fine but is not not exactly what i am trying to do, maybe i did not explain it it well, i don't need 3 days in that full format

the english version maybe helps a bit
Image

that is what i have working so far with the "not optimized" code with all the lines manually coded for each case of the conditions

what the skin needs to show is the name of the 3 days ( yesterday, today, tomorrow ), highlighting today's day ( same with the day number and month name )

that is why i need to have the 9 variables/ pieces of text to show and not 3 full format date

super simple version of what i have , showing the day number that is the longer one with 31 options
https://paste2.org/5ZBEChZ7
yesterday was 3 , today is 4 ( with inline format) and tomorrow is 5
( #numeromenos# = yesterday = 3 , #numero# = today = 4 , #numeromas# = tomorrow = 5 )
Image

my issue : code just to show that is 71 lines , i am trying to make lines 4 to 65 ( 62) in maybe 6 combining all the 31 numbers in 3 cases ( 1 , 2 to 30 , 31 )
my failed idea:

Code: Select all

[MeasureNumber]
Measure=Time
Format=%#d
IfCondition=MeasureNumber = 1
IfTrueAction=[!SetOption Number InlinePattern " 1 "]|[!SetVariable NumberYesterday 31]|[!SetVariable NumberToday 1]|[!SetVariable NumberTomorrow 2]
IfCondition2= ( MeasureNumber >=2 )&&( MeasureNumber <=30 )
IfTrueAction2=[!SetOption Number InlinePattern MeasureNumber]|[!SetVariable NumberYesterday (MeasureNumber-1)]|[!SetVariable NumberToday MeasureNumber]|[!SetVariable NumberTomorrow (MeasureNumber+1)]
IfCondition3=MeasureNumber = 31
IfTrueAction3=[!SetOption Number InlinePattern " 31 "]|[!SetVariable NumberYesterday 30]|[!SetVariable  NumberToday 31]|[!SetVariable NumberTomorrow 1]
IfConditionMode=1

[Number]
Meter=String
FontColor=255,255,255,255
FontSize=32
Text=#NumberYesterday# #NumberToday# #NumberTomorrow#
InlineSetting=Color | 255,0,0,255
so questions :
1) how do i need to use something like

Code: Select all

!SetVariable variablename measurename+1
? ( being 4 today that i get with the measure so get 5 for tomorrow , only the 5 , not the full Format=%#c )
2) in

Code: Select all

!SetOption metername InlinePattern  XYZ
, how i add a space before and after the XYZ string ( reason to use space in my first post )
User avatar
balala
Rainmeter Sage
Posts: 13719
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: help to simplify a bunch of IfCondition

Post by balala »

To be honest I just read the post, but at least as far as I can say, there is no need to create conditions. Don't complicate things. Would be nice you to post the whole code of your skin, maybe there is a simply way to achieve what you want.
So waiting for the whole code...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4581
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: help to simplify a bunch of IfCondition

Post by eclectic-tech »

Seeing all of your code would make it easier to help.

But you misunderstood my suggestion:
Simply use those 3 measures to determine yesterday, today, and tomorrow.

This way completely eliminates any need to test all the days of the month in IfConditions tests.

Here is my code with days as measure values and a combined string meter that will give you the desired result:

Code: Select all

; ========= Metadata ==========
[Metadata]
Name=
Author=
Information=
; BY=attribution / SA=share-alike / ND=no-derivatives / NC=non-commercial
License=CC BY-SA-NC 3.0
Version=

; ========= Variables ==========
[Variables]


; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#

; ========= Measures ==========
[MeasureToday]
Measure=Time
Format=%#d
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes

[MeasureYesterday]
Measure=Time
Format=%#d
TimeStamp=([MeasureToday:TimeStamp]-86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


[MeasureTomorrow]
Measure=Time
Format=%#d
TimeStamp=([MeasureToday:TimeStamp]+86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


; ========= Meter Styles ==========



; ========= Meters ==========
[Number]
Meter=String
MeasureName=MeasureYesterday
MeasureName2=MeasureToday
MeasureName3=MeasureTomorrow
FontColor=220,220,220
FontSize=18
Text=%1 %2 %3
InlinePattern=[MeasureToday]
InlineSetting=Color | 255,0,0
Antialias=1
X=30
StringAlign=Center
3daysN.png
You do not have the required permissions to view the files attached to this post.
User avatar
carlitosbahia
Posts: 12
Joined: December 30th, 2021, 10:32 pm

Re: help to simplify a bunch of IfCondition

Post by carlitosbahia »

balala wrote: January 4th, 2022, 10:24 am To be honest I just read the post, but at least as far as I can say, there is no need to create conditions. Don't complicate things. Would be nice you to post the whole code of your skin, maybe there is a simply way to achieve what you want.
So waiting for the whole code...
yes, i could see that what i want to do with the months ( previous and next month, not month of previous and next day ) is probably not what most people would want to do in this type of skin :D
but also would be nice to learn for future skins how i can do that simple math with some variables ( forget about being dates for a second , just any variables ) using a !setvariable inside a IfTrueAction


Full Skin

Code: Select all

https://www.mediafire.com/file/lf8c9pbg8cnq502/YADTS_BeforeAfter.7z/file



**********************************************************************************************************************************************************


eclectic-tech wrote: January 4th, 2022, 2:27 pm Seeing all of your code would make it easier to help.

But you misunderstood my suggestion:
Simply use those 3 measures to determine yesterday, today, and tomorrow.

This way completely eliminates any need to test all the days of the month in IfConditions tests.

Here is my code with days as measure values and a combined string meter that will give you the desired result:
Full Skin

Code: Select all

https://www.mediafire.com/file/lf8c9pbg8cnq502/YADTS_BeforeAfter.7z/file
ah , ok, yeah, now i see i could do what i want , timestamp does not work only with Format=%#c and the full date but i can use it for the day number ( %e or %d ) and for the weekday ( %A )
Image
Image

but, tried with the month ( %b or %B ) and all i get is January 3 times , and of course all highlighted
Image

that makes sense, yesterday and tomorrow are still the same month but just not what i want to do , there i would like to show "December January February" , so really previous and next months and not month of previous and next day, if that makes sense

so for the month i would need to still use the conditions , at least 12 are less than 31, so that is better

other time where i think i still need to use the conditions is when i have the spanish version of the skin , my windows is in english so i would need to translate that manually both for weekday and month

like i said, skin is working fine as it is even when code is not the prettiest , if i were using other language where we had vectors or loops for sure will not do it this way :D
but also would be nice to learn for future skins how i can do that simple math with some variables ( forget about being dates for a second , just any variables ) using a !setvariable inside a IfTrueAction
Last edited by carlitosbahia on January 4th, 2022, 5:03 pm, edited 1 time in total.
User avatar
death.crafter
Rainmeter Sage
Posts: 1293
Joined: April 24th, 2021, 8:13 pm

Re: help to simplify a bunch of IfCondition

Post by death.crafter »

carlitosbahia wrote: January 4th, 2022, 6:29 am so questions :
1) how do i need to use something like

Code: Select all

!SetVariable variablename measurename+1
? ( being 4 today that i get with the measure so get 5 for tomorrow , only the 5 , not the full Format=%#c )
2) in

Code: Select all

!SetOption metername InlinePattern  XYZ
, how i add a space before and after the XYZ string ( reason to use space in my first post )
Answering your questions,
  1. Code: Select all

    ; the paranthesis are required where arithmetic operations are done
    ; [SectionVariable] is used to get the string value of a measure in a line of code, use a colon(:) after it to force numeric value.
    ; In most cases tho, as in your case, both string and numeric values are numeric, so no need of colon postfix.
    ; ===============================
    SomeAction=[!SetVariable VariableName "([MeasureName]+1)"]
    ; ===============================
    
  2. Code: Select all

    ; you can use quotes to use spaces at start or end, but while setting an option's value, starting and ending 
    ; white spaces are ignored
    ; but it's a regex pattern and we could do it as
    ; ===============================
    SomeAction=[!SetOption metername InlinePattern  "\sXYZ\s"]
    ; ===============================
    ; since \s denotes white space character
    
Apart from above things see eclectic-tech's code. Another illustration of the same would be:

Code: Select all

; ========= Metadata ==========
[Metadata]
Name=
Author=
Information=
; BY=attribution / SA=share-alike / ND=no-derivatives / NC=non-commercial
License=CC BY-SA-NC 3.0
Version=

; ========= Variables ==========
[Variables]


; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#

; ========= Measures ==========
[MeasureToday]
Measure=Time
Format=%A
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes

[MeasureYesterday]
Measure=Time
Format=%A
TimeStamp=([MeasureToday:TimeStamp]-86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


[MeasureTomorrow]
Measure=Time
Format=%A
TimeStamp=([MeasureToday:TimeStamp]+86400)
DynamicVariables=1
; Documentation: Format Codes https://docs.rainmeter.net/manual-beta/measures/time/#FormatCodes


; ========= Meter Styles ==========



; ========= Meters ==========
[Number]
Meter=String
MeasureName=MeasureYesterday
MeasureName2=MeasureToday
MeasureName3=MeasureTomorrow
FontFace=Segoe Script
FontColor=200,200,200
FontSize=18
Text=%1 %2 %3
InlinePattern=[MeasureToday:EscapeRegExp]
InlineSetting=Color | 255,255,255
InlinePattern2=[MeasureToday:EscapeRegExp]
InlineSetting2=Shadow | 0 | 0 | 5 | 255,255,255
Antialias=1
Padding=5,5,5,5
Screenshot 2022-01-04 223126.png
You do not have the required permissions to view the files attached to this post.
from the Realm of Death
User avatar
carlitosbahia
Posts: 12
Joined: December 30th, 2021, 10:32 pm

Re: help to simplify a bunch of IfCondition

Post by carlitosbahia »

oh, nice, i was just sending a reply
yeah, i never included the [ ] in my tests , i will look into it, and of course regex are involved, damn, lol

Thanks!!!!
User avatar
balala
Rainmeter Sage
Posts: 13719
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: help to simplify a bunch of IfCondition

Post by balala »

carlitosbahia wrote: January 4th, 2022, 5:02 pm yes, i could see that what i want to do with the months ( previous and next month, not month of previous and next day ) is probably not what most people would want to do in this type of skin :D
but also would be nice to learn for future skins how i can do that simple math with some variables ( forget about being dates for a second , just any variables ) using a !setvariable inside a IfTrueAction
Apart from the next posts here is an example of code, which does what is required without setting those variables. Yep, I saw death.crafter's code, however if I'm not mistaken, even if it does work for weekdays and dates, it doesn't for month. The months have the problem of variable lengths. How many days are you adding / extracting from the time stamp of a Time measure returning current day, to get the name of previous / next month, no matter of date? What I mean is that for instance on Jan 1 you have to add 31 days (31 x 86400 seconds) to get the name of next month (February), but if you add the same 31 days on Jan 31, you get March instead of February, because February has only 28 (or in leap years 29) days, so adding 31 days is too much in such a case. To fix this, you have to add a variable number of days. See the TimeStamp option of the [MeasurePrevMonth] and [MeasureNextMonth] measures of the below code.
I didn't remove so far all those IfCondition and IfTrueAction options from the Time measures, just commented them out, to let you see how much easier and shorter is such a code. But in fact they are not needed anymore, you can freely remove them. In this approach there is also not needed to set too complicated InlinePatters. They are handled "on fly" in the String meters themselves ([Day], [Number] and [Month]).
If you want, please test the code and let me know what you think.

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!Move "(#WORKAREAWIDTH#-435-20)" 20]
AccurateText=1

[Metadata]
Name=YetAnotherDateTimeSkin BeforeAFter
Author=CarlitosBahia
Information=First try to make a date/time skin - added Before After
Version=1.0.0
License=Whatever

[Variables]
FontName=Dealerplate California
FontClockSize=90
FontAMPMSize=60
FontMainSize=20
FontFullColor=255,255,255,255
FontDimmedColor=255,255,255,80
Dia=""
DiaMenos=""
DiaMas=""
Numero=""
NumeroMenos=""
NumeroMas=""
Mes=""
Mesmenos=""
MesMas=""

[MeterBack]
Meter=Shape
Shape=Rectangle 0,0,435,240,20 | Fill Color 252,255,225,50 | StrokeWidth 0

; =====> CLOCK
[MeasureClock]
Measure=Time
Format=%I %M

[MeterClock]
Meter=String
MeasureName=MeasureClock
FontFace=#FontName#
FontColor=#FontFullColor#
FontSize=#FontClockSize#
StringAlign=Right
AntiAlias=1
X=235
Y=0

; =====> SECONDS
[MeasureSecs]
Measure=Time
Format=%S

[MeterSecs]
Meter=String
MeasureName=MeasureSecs
FontFace=#FontName#
FontColor=#FontFullColor#
FontSize=#FontAMPMSize#
StringAlign=Center
AntiAlias=1
X=50r
Y=23r

; =====> AM/PM
[MeasureAMPM]
Measure=Time
Format=%p

[MeterAMPM]
Meter=String
MeasureName=MeasureAMPM
FontFace=#FontName#
FontColor=#FontFullColor#
FontSize=#FontAMPMSize#
StringAlign=Center
AntiAlias=1
X=80r
Y=0r

; =====> SUN-SAT
[MeasureDay]
Measure=Time
Format=%A
;IfCondition=MeasureDay = 1
;IfTrueAction=[!SetOption Day InlinePattern MONDAY][!SetVariable DiaMenos SUNDAY][!SetVariable Dia MONDAY][!SetVariable DiaMas TUESDAY] 
;IfCondition2=MeasureDay = 2
;IfTrueAction2=[!SetOption Day InlinePattern TUESDAY][!SetVariable DiaMenos MONDAY][!SetVariable Dia TUESDAY][!SetVariable DiaMas WEDNESDAY]
;IfCondition3=MeasureDay = 3
;IfTrueAction3=[!SetOption Day InlinePattern WEDNESDAY][!SetVariable DiaMenos TUESDAY][!SetVariable Dia WEDNESDAY][!SetVariable DiaMas THURSDAY] 
;IfCondition4=MeasureDay = 4
;IfTrueAction4=[!SetOption Day InlinePattern THURSDAY][!SetVariable DiaMenos WEDNESDAY][!SetVariable Dia THURSDAY][!SetVariable DiaMas FRIDAY] 
;IfCondition5=MeasureDay = 5
;IfTrueAction5=[!SetOption Day InlinePattern FRIDAY][!SetVariable DiaMenos THURSDAY][!SetVariable Dia FRIDAY][!SetVariable DiaMas SATURDAY] 
;IfCondition6=MeasureDay = 6
;IfTrueAction6=[!SetOption Day InlinePattern SATURDAY][!SetVariable DiaMenos FRIDAY][!SetVariable Dia SATURDAY][!SetVariable DiaMas SUNDAY] 
;IfCondition7=(MeasureDay = 7)
;IfTrueAction7=[!SetOption Day InlinePattern SUNDAY][!SetVariable DiaMenos SATURDAY][!SetVariable Dia SUNDAY][!SetVariable DiaMas MONDAY]

[MeasurePrevDay]
Measure=Time
Format=%A
TimeStamp=([MeasureNumber:TimeStamp]-86400)
DynamicVariables=1

[MeasureNextDay]
Measure=Time
Format=%A
TimeStamp=([MeasureNumber:TimeStamp]+86400)
DynamicVariables=1

[Day]
Meter=String
MeasureName=MeasurePrevDay
MeasureName2=MeasureDay
MeasureName3=MeasureNextDay
FontFace=#FontName#
FontSize=#FontMainSize#
FontColor=#FontDimmedColor#
Text=%1 %2 %3
InlineSetting=Color | #FontFullColor#
InlinePattern=[MeasureDay]
Antialias=1
StringAlign=Center
X=215
Y=5R
DynamicVariables=1

; =====> 1-31

[MeasureNumber]
Measure=Time
Format=%#d
;IfCondition=MeasureNumber = 1
;IfTrueAction=[!SetOption Number InlinePattern " 1 "][!SetVariable NumeroMenos 31][!SetVariable Numero 1][!SetVariable NumeroMas 2]
;IfCondition2=MeasureNumber = 2
;IfTrueAction2=[!SetOption Number InlinePattern " 2 "][!SetVariable NumeroMenos 1][!SetVariable Numero 2][!SetVariable NumeroMas 3]
;IfCondition3=MeasureNumber = 3
;IfTrueAction3=[!SetOption Number InlinePattern " 3 "][!SetVariable NumeroMenos 2][!SetVariable Numero 3][!SetVariable NumeroMas 4]
;IfCondition4=MeasureNumber = 4
;IfTrueAction4=[!SetOption Number InlinePattern " 4 "][!SetVariable NumeroMenos 3][!SetVariable Numero 4][!SetVariable NumeroMas 5]
;IfCondition5=MeasureNumber = 5
;IfTrueAction5=[!SetOption Number InlinePattern " 5 "][!SetVariable NumeroMenos 4][!SetVariable Numero 5][!SetVariable NumeroMas 6]
;IfCondition6=MeasureNumber = 6
;IfTrueAction6=[!SetOption Number InlinePattern " 6 "][!SetVariable NumeroMenos 5][!SetVariable Numero 6][!SetVariable NumeroMas 7]
;IfCondition7=MeasureNumber = 7
;IfTrueAction7=[!SetOption Number InlinePattern " 7 "][!SetVariable NumeroMenos 6][!SetVariable Numero 7][!SetVariable NumeroMas 8]
;IfCondition8=MeasureNumber = 8
;IfTrueAction8=[!SetOption Number InlinePattern " 8 "][!SetVariable NumeroMenos 7][!SetVariable Numero 8][!SetVariable NumeroMas 9]
;IfCondition9=MeasureNumber = 9
;IfTrueAction9=[!SetOption Number InlinePattern " 9 "][!SetVariable NumeroMenos 8][!SetVariable Numero 9][!SetVariable NumeroMas 10]
;IfCondition10=MeasureNumber = 10
;IfTrueAction10=[!SetOption Number InlinePattern " 10 "][!SetVariable NumeroMenos 9][!SetVariable Numero 10][!SetVariable NumeroMas 11]
;IfCondition11=MeasureNumber = 11
;IfTrueAction11=[!SetOption Number InlinePattern " 11 "][!SetVariable NumeroMenos 10][!SetVariable Numero 11][!SetVariable NumeroMas 12]
;IfCondition12=MeasureNumber = 12
;IfTrueAction12=[!SetOption Number InlinePattern " 12 "][!SetVariable NumeroMenos 11][!SetVariable Numero 12][!SetVariable NumeroMas 13]
;IfCondition13=MeasureNumber = 13
;IfTrueAction13=[!SetOption Number InlinePattern " 13 "][!SetVariable NumeroMenos 12][!SetVariable Numero 13][!SetVariable NumeroMas 14]
;IfCondition14=MeasureNumber = 14
;IfTrueAction14=[!SetOption Number InlinePattern " 14 "][!SetVariable NumeroMenos 13][!SetVariable Numero 14][!SetVariable NumeroMas 15]
;IfCondition15=MeasureNumber = 15
;IfTrueAction15=[!SetOption Number InlinePattern " 15 "][!SetVariable NumeroMenos 14][!SetVariable Numero 15][!SetVariable NumeroMas 16]
;IfCondition16=MeasureNumber = 16
;IfTrueAction16=[!SetOption Number InlinePattern " 16 "][!SetVariable NumeroMenos 15][!SetVariable Numero 16][!SetVariable NumeroMas 17]
;IfCondition17=MeasureNumber = 17
;IfTrueAction17=[!SetOption Number InlinePattern " 17 "][!SetVariable NumeroMenos 16][!SetVariable Numero 17][!SetVariable NumeroMas 18]
;IfCondition18=MeasureNumber = 18
;IfTrueAction18=[!SetOption Number InlinePattern " 18 "][!SetVariable NumeroMenos 17][!SetVariable Numero 18][!SetVariable NumeroMas 19]
;IfCondition19=MeasureNumber = 19
;IfTrueAction19=[!SetOption Number InlinePattern " 19 "][!SetVariable NumeroMenos 18][!SetVariable Numero 19][!SetVariable NumeroMas 20]
;IfCondition20=MeasureNumber = 20
;IfTrueAction20=[!SetOption Number InlinePattern " 20 "][!SetVariable NumeroMenos 19][!SetVariable Numero 20][!SetVariable NumeroMas 21]
;IfCondition21=MeasureNumber = 21
;IfTrueAction21=[!SetOption Number InlinePattern " 21 "][!SetVariable NumeroMenos 20][!SetVariable Numero 21][!SetVariable NumeroMas 22]
;IfCondition22=MeasureNumber = 22
;IfTrueAction22=[!SetOption Number InlinePattern " 22 "][!SetVariable NumeroMenos 21][!SetVariable Numero 22][!SetVariable NumeroMas 23]
;IfCondition23=MeasureNumber = 23
;IfTrueAction23=[!SetOption Number InlinePattern " 23 "][!SetVariable NumeroMenos 22][!SetVariable Numero 23][!SetVariable NumeroMas 24]
;IfCondition24=MeasureNumber = 24
;IfTrueAction24=[!SetOption Number InlinePattern " 24 "][!SetVariable NumeroMenos 23][!SetVariable Numero 24][!SetVariable NumeroMas 25]
;IfCondition25=MeasureNumber = 25
;IfTrueAction25=[!SetOption Number InlinePattern " 25 "][!SetVariable NumeroMenos 24][!SetVariable Numero 25][!SetVariable NumeroMas 26]
;IfCondition26=MeasureNumber = 26
;IfTrueAction26=[!SetOption Number InlinePattern " 26 "][!SetVariable NumeroMenos 25][!SetVariable Numero 26][!SetVariable NumeroMas 27]
;IfCondition27=MeasureNumber = 27
;IfTrueAction27=[!SetOption Number InlinePattern " 27 "][!SetVariable NumeroMenos 26][!SetVariable Numero 27][!SetVariable NumeroMas 28]
;IfCondition28=MeasureNumber = 28
;IfTrueAction28=[!SetOption Number InlinePattern " 28 "][!SetVariable NumeroMenos 27][!SetVariable Numero 28][!SetVariable NumeroMas 29]
;IfCondition29=MeasureNumber = 29
;IfTrueAction29=[!SetOption Number InlinePattern " 29 "][!SetVariable NumeroMenos 28][!SetVariable Numero 29][!SetVariable NumeroMas 30]
;IfCondition30=MeasureNumber = 30
;IfTrueAction30=[!SetOption Number InlinePattern " 30 "][!SetVariable NumeroMenos 29][!SetVariable Numero 30][!SetVariable NumeroMas 31]
;IfCondition31=MeasureNumber = 31
;IfTrueAction31=[!SetOption Number InlinePattern " 31 "][!SetVariable NumeroMenos 30][!SetVariable Numero 31][!SetVariable NumeroMas 1]

[MeasureYesterday]
Measure=Time
Format=%#d
TimeStamp=([MeasureNumber:TimeStamp]-86400)
DynamicVariables=1

[MeasureTomorrow]
Measure=Time
Format=%#d
TimeStamp=([MeasureNumber:TimeStamp]+86400)
DynamicVariables=1

[Number]
Meter=String
MeasureName=MeasureYesterday
MeasureName2=MeasureNumber
MeasureName3=MeasureTomorrow
FontFace=#FontName#
FontColor=#FontDimmedColor#
FontSize=#FontMainSize#
Text=%1 %2 %3
InlineSetting=Color | #FontFullColor#
InlinePattern=[MeasureNumber]
Antialias=1
StringAlign=Center
X=215
Y=0R
DynamicVariables=1

; =====> JAN-DEC 
[MeasureMonth]
Measure=Time
Format=%b
;IfMatch=Jan
;IfMatchAction=[!SetOption Month InlinePattern JANUARY][!SetVariable MesMenos DECEMBER][!SetVariable Mes JANUARY][!SetVariable MesMas FEBRAURY]
;IfMatch2=Feb
;IfMatchAction2=[!SetOption Month InlinePattern FEBRAURY][!SetVariable MesMenos JANUARY][!SetVariable Mes FEBRAURY][!SetVariable MesMas MARCH]
;IfMatch3=Mar
;IfMatchAction3=[!SetOption Month InlinePattern MARCH][!SetVariable MesMenos FEBRAURY][!SetVariable Mes MARCH][!SetVariable MesMas APRIL] 
;IfMatch4=Apr
;IfMatchAction4=[!SetOption Month InlinePattern APRIL][!SetVariable MesMenos MARCH][!SetVariable Mes APRIL][!SetVariable MesMas MAY] 
;IfMatch5=May
;IfMatchAction5=[!SetOption Month InlinePattern MAY][!SetVariable MesMenos APRIL][!SetVariable Mes MAY][!SetVariable MesMas JUNE] 
;IfMatch6=Jun
;IfMatchAction6=[!SetOption Month InlinePattern JUNE][!SetVariable MesMenos MAY][!SetVariable Mes JUNE][!SetVariable MesMas JULY]
;IfMatch7=July
;IfMatchAction7=[!SetOption Month InlinePattern JULY][!SetVariable MesMenos JUNE][!SetVariable Mes JULY][!SetVariable MesMas AUGUST]
;IfMatch8=Aug
;IfMatchAction8=[!SetOption Month InlinePattern AUGUST][!SetVariable MesMenos JULY][!SetVariable Mes AUGUST][!SetVariable MesMas SEPTEMBER]
;IfMatch9=Sept
;IfMatchAction9=[!SetOption Month InlinePattern SEPTEMBER][!SetVariable MesMenos AUGUST][!SetVariable Mes SEPTEMBER][!SetVariable MesMas OCTOBER]
;IfMatch10=Oct
;IfMatchAction10=[!SetOption Month InlinePattern OCTOBER][!SetVariable MesMenos SEPTEMBER][!SetVariable Mes OCTOBER][!SetVariable MesMas NOVEMBER]
;IfMatch11=Nov
;IfMatchAction11=[!SetOption Month InlinePattern NOVEMBER][!SetVariable MesMenos OCTOBER][!SetVariable Mes NOVEMBER][!SetVariable MesMas DECEMBER]
;IfMatch12=Dic
;IfMatchAction12=[!SetOption Month InlinePattern DECEMBER][!SetVariable MesMenos NOVEMBER][!SetVariable Mes DECEMBER][!SetVariable MesMas JANUARY]

[MeasurePrevMonth]
Measure=Time
Format=%b
TimeStamp=([MeasureNumber:TimeStamp]-31*86400+(([MeasureNumber]<5)*10*86400))
DynamicVariables=1

[MeasureNextMonth]
Measure=Time
Format=%b
TimeStamp=([MeasureNumber:TimeStamp]+31*86400-(([MeasureNumber]>25)*10*86400))
DynamicVariables=1

[Month]
Meter=String
MeasureName=MeasurePrevMonth
MeasureName2=MeasureMonth
MeasureName3=MeasureNextMonth
FontFace=#FontName#
FontColor=#FontDimmedColor#
FontSize=#FontMainSize#
Text=%1 %2 %3
InlineSetting=Color | #FontFullColor#
InlinePattern=[MeasureMonth]
Antialias=1
StringAlign=Center
X=215
Y=0R
DynamicVariables=1
User avatar
carlitosbahia
Posts: 12
Joined: December 30th, 2021, 10:32 pm

Re: help to simplify a bunch of IfCondition

Post by carlitosbahia »

thanks!
yes , i already had the clock, day of the week and number of day modifying my old code, i reduced around 60 lines using this method :thumbup:
https://paste2.org/Yjkzn3NI

i was still thinking about the month issue, i thought about adding the 31 days in seconds but then i realized the same that you did, not all the months are 31 days long , i was stuck there

now, looking at your code for the month

[MeasurePrevMonth]
TimeStamp=([MeasureNumber:TimeStamp]-31*86400+(([MeasureNumber]<5)*10*86400))

you substract the 31 days , ok , but i am not totally sure about the second part
(([MeasureNumber]<5)*10*86400)

i assume that is rainmeter way to say If [MeasureNumber]<5 then make that 1 , else then make it 0 ?
( kind of a shorter ternary operator in js ? )