It is currently July 21st, 2019, 3:39 am
Help with creating, editing & fixing problems with skins

StArL0rd84
 Posts: 336
 Joined: February 8th, 2015, 10:07 pm
 Location: EU, Denmark.
StArL0rd84 » February 12th, 2019, 12:53 pm
I am making a folder launcher skin with the feature to adjust the number of folders that is visible.
The maximum number of folders is 16, and should you hit the max, the skin should go back to 1 and start over.
And vice versa in the other direction.
This bang works perfectly when counting up: (Counts from 1)
[!SetVariable "NumberofFolders" "#NumberofFolders#%16+1"]
But i can only find the following formula to count down and wrap back around to 16:
Problem is that it counts to 0, and THEN 1.
[!SetVariable "NumberofFolders" "(#NumberofFolders#1+(16+1))%(16+1)"]
I bet it's as simple as moving around or deleting a few parentheses, but i just can't see it.
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))

balala
 Rainmeter Sage
 Posts: 8390
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
balala » February 12th, 2019, 1:20 pm
Something like this maybe:
[!SetVariable NumberofFolders "(((#NumberofFolders#1)<1)?16:(#NumberofFolders#1))"]. With this formula you can control easily both, when to wrap back to the largest possible value (through the red parameter above) and this largest value (16 in this case).
StArL0rd84 wrote: ↑February 12th, 2019, 12:53 pm
[!SetVariable "NumberofFolders" "#NumberofFolders#%16+1"]
To be honest I think some parenthesis are needed here. Correctly it would be:
[!SetVariable "NumberofFolders" "(#NumberofFolders#%16+1)"]

StArL0rd84
 Posts: 336
 Joined: February 8th, 2015, 10:07 pm
 Location: EU, Denmark.
StArL0rd84 » February 12th, 2019, 1:32 pm
balala wrote: ↑February 12th, 2019, 1:20 pm
Something like this maybe:
[!SetVariable NumberofFolders "(((#NumberofFolders#1)<1)?16:(#NumberofFolders#1))"]. With this formula you can control easily both, when to wrap back to the largest possible value (through the red parameter above) and this largest value (16 in this case).
To be honest I think some parenthesis are needed here. Correctly it would be:
[!SetVariable "NumberofFolders" "(#NumberofFolders#%16+1)"]
I see what you did there. And it works great
I think i understand it fully now:
Is #NumberofFolders#1 less than 1? then it's 16. If not then it's #NumberofFolders#1.
And for counting up:
(((#NumberofFolders#+1)>16)?1:(#NumberofFolders#+1))
(#WorkTime# = 1 ? #Work# : ([mEnergyLoss:%] > 100 ? #SleepMode# : #Rainmeter#))

balala
 Rainmeter Sage
 Posts: 8390
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
balala » February 12th, 2019, 1:36 pm
StArL0rd84 wrote: ↑February 12th, 2019, 1:32 pm
I see what you did there. And it works great
I think i understand it fully now:
Is #NumberofFolders#1 less than 1? then it's 16. If not then it's #NumberofFolders#1.
Exactly. Probably not too tricky, but usually it works and is very efficient, being easy to modify, if needed.

jsmorley
 Developer
 Posts: 19301
 Joined: April 19th, 2009, 11:02 pm
 Location: Fort Hunt, Virginia, USA
jsmorley » February 12th, 2019, 1:37 pm
StArL0rd84 wrote: ↑February 12th, 2019, 1:32 pm
I see what you did there. And it works great
I think i understand it fully now:
Is #NumberofFolders#1 less than 1? then it's 16. If not then it's #NumberofFolders#1.
And for counting up:
(((#NumberofFolders#+1)>16)?1:(#NumberofFolders#+1))
Correct.
https://docs.rainmeter.net/manual/formulas/#Conditional
https://en.wikipedia.org/wiki/%3F:

balala
 Rainmeter Sage
 Posts: 8390
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
balala » February 12th, 2019, 1:42 pm
StArL0rd84 wrote: ↑February 12th, 2019, 1:32 pm
And for counting up:
(((#NumberofFolders#+1)>16)?1:(#NumberofFolders#+1))
Yes, for counting up this can help.
If you count up and is good to wrap back to 0 when you reach the largest value (in this case 16), probably the easiest formula is
[!SetVariable "NumberofFolders" "((#NumberofFolders#+1)%17)"]. But if you want to wrap back not to 0, but to 1 (or to any other value), this is ok.

qwerky
 Posts: 181
 Joined: April 10th, 2014, 12:31 am
 Location: Canada
qwerky » April 15th, 2019, 7:09 pm
balala wrote: ↑February 12th, 2019, 1:20 pm
Something like this maybe:
[!SetVariable NumberofFolders "(((#NumberofFolders#1)<1)?16:(#NumberofFolders#1))"]. With this formula you can control easily both, when to wrap back to the largest possible value (through the red parameter above) and this largest value (16 in this case).
Just recently I was working on the same issue: counting down and resetting to the largest value when reaching one, rather than when reaching zero. I knew it could be done with the conditional operator, but was thinking that doing it with the modulus operator would be nice, as it would be symmetrical with the count up loop.
But after banging my head against this wall for a while
, I decided to search the forums, and came upon this thread. So I wondered, if that example were rewritten like this:
[!SetVariable NumberofFolders "((#NumberofFolders#=1)?16:(#NumberofFolders#1))"] one would save a few CPU cycles by doing the subtraction only once; but the savings would likely be entirely negligible on modern systems. [It's just the old machinelanguage/assemblylanguage programmer in me fighting for every cycle!
]
But just out of interest, can anyone come up with a modulusbased formula for this?
In that Wikipedia article, I loved the case selector example.

balala
 Rainmeter Sage
 Posts: 8390
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
balala » April 15th, 2019, 7:38 pm
qwerky wrote: ↑April 15th, 2019, 7:09 pm
But just out of interest, can anyone come up with a modulusbased formula for this?
For example, in the following code you have to set the limits of counting. There are two variables, Min and Max, which probably you've figured out what do mean:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
Min=5
Max=18
[MeasureCount]
Measure=Calc
Formula=(( MeasureCount + 1 ) % ( #Max#  #Min# + 1 ))
[MeasureCountDown]
Measure=Calc
Formula=( #Max#  MeasureCount )
[MeterTest]
Meter=String
MeasureName=MeasureCountDown
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=15,5,15,5
AntiAlias=1
Text=Count down: %1#CRLF#(Limits: #Min# and #Max#)
Unfortunately as you can see I had to use two measures, to make the count down. Probably it's not possible to make it, using one single measure (me at least couldn't find a way to do this in a such way).
You can set even negative limits (for example try the
Min=5 and
Max=12 variables)

qwerky
 Posts: 181
 Joined: April 10th, 2014, 12:31 am
 Location: Canada
qwerky » April 16th, 2019, 12:54 am
balala wrote: ↑April 15th, 2019, 7:38 pm
For example, in the following code you have to set the limits of counting. There are two variables, Min and Max, which probably you've figured out what do mean:
Unfortunately as you can see I had to use two measures, to make the count down. Probably it's not possible to make it, using one single measure (me at least couldn't find a way to do this in a such way).
You can set even negative limits (for example try the
Min=5 and
Max=12 variables)
Thanks, balala; appreciate your taking the time to look at it. I believe the following formula will count down to one, and loop:
(((#counter#+#counterMax#2)%#counterMax#)+1)
and present the following data for counterMax=7:
Code: Select all
OOB 9 + 7  2 = 14 % 7 = 7 + 1 = 8
OOB 8 + 7  2 = 13 % 7 = 6 + 1 = 7
Max 7 + 7  2 = 12 % 7 = 5 + 1 = 6
6 + 7  2 = 11 % 7 = 4 + 1 = 5
5 + 7  2 = 10 % 7 = 3 + 1 = 4
4 + 7  2 = 9 % 7 = 2 + 1 = 3
3 + 7  2 = 8 % 7 = 1 + 1 = 2
2 + 7  2 = 7 % 7 = 0 + 1 = 1
Loop 1 + 7  2 = 6 % 7 = 6 + 1 = 7
OOB 0 + 7  2 = 5 % 7 = 5 + 1 = 6
OOB 1 + 7  2 = 4 % 7 = 4 + 1 = 5
where OOB = out of bounds. This was designed simply to count down by one, from a maximum to one, and then loop back to maximum. No consideration was given to increments other than one. Nor was consideration given to outofbound starting numbers, although it appears to automatically bring such back into bounds. Having some extra sets of eyes look it over would be helpful.
This isn't necessarily better than using the conditional operator, but does satisfy the requirements of using the modulus operator to be symmetrical with countup loop.

balala
 Rainmeter Sage
 Posts: 8390
 Joined: October 11th, 2010, 6:27 pm
 Location: Gheorgheni, Romania
balala » April 16th, 2019, 7:34 am
qwerky wrote: ↑April 16th, 2019, 12:54 am
(((#counter#+#counterMax#2)%#counterMax#)+1)
Well, good, just that the Formula should have to be:
Code: Select all
[MeasureCount]
...
Formula=(((MeasureCount+#counterMax#2)%#counterMax#)+1)
(supposing as can be seen above that the measure is named [MeasureCount]).
By simply using your Formula won't change the value of the counter variable and the measure won't count down.
Otherwise congratulations, as you can see, as well as many other times, here are more possible solutions, from which we can choose if we need to.