It is currently February 20th, 2019, 8:28 pm

Counting down to 1 instead of 0

Help with creating, editing & fixing problems with skins
User avatar
StArL0rd84
Posts: 275
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Counting down to 1 instead of 0

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.
Image
User avatar
balala
Rainmeter Sage
Posts: 7674
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting down to 1 instead of 0

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)"]
User avatar
StArL0rd84
Posts: 275
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Counting down to 1 instead of 0

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))
User avatar
balala
Rainmeter Sage
Posts: 7674
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting down to 1 instead of 0

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.
User avatar
jsmorley
Developer
Posts: 18869
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Counting down to 1 instead of 0

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:
User avatar
balala
Rainmeter Sage
Posts: 7674
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Counting down to 1 instead of 0

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.