It is currently March 29th, 2024, 12:45 am

Loop Measure Question = How To Prevent Infinite Loop [solved]

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Loop Measure Question = How To Prevent Infinite Loop [solved]

Post by CodeCode »

Hello.

I want a variable to increment by 1, 5 times, then stop until another action resets it to begin again.

I imagine it like this:

Code: Select all

[MeasureOne]
Measure=String
String=[#FolderOne]
IfMatch=^$
IfMatchAction=[!SetVariable FolderOne [#FolderSet]][!WriteKeyValue Variables FolderOne [#FolderSet] "#@#TitanVars.inc"][!UnPauseMeasure FolderLoopState][!UpdateMeter MeterOne]
IfNotMatchAction=[!UpdateMeasure "MeasureTwo"]
IfMatch2=^THIS PC$
IfMatchAction2=[!SetOption MeterOne Hidden "1"][!SetVariable LoopEnd ((#LoopEnd#+1)?5:[!PauseMeasure FolderLoopState])]
IfNotMatchAction2=[!SetOption MeterOne Hidden "0"]
DynamicVariables=1

[FolderLoopState]
Measure=Loop
StartValue=0
EndValue=#LoopEnd#
Increment=1
LoopCount=1
But I know that will not work.
I ask for help, since testing will lead to unnecessary rainmeter crashes.

The Increment will advance the variable #FolderState# in this one of five similar Measures. :

Code: Select all

[MeasureFolderMode]
Measure=Calc
Formula=0
IfCondition=(#FolderState# = 1)
IfTrueAction=[!SetOption MeterOne Hidden "0"][!SetVariable FolderOne ""][!WriteKeyValue Variables FolderOne "" "#@#TitanVars.inc"][!SetOption mPath "Path" ""][!CommandMeasure mPath "Update"][!UpdateMeter *][!Redraw]
Last edited by CodeCode on December 24th, 2021, 6:43 am, edited 1 time in total.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by balala »

There is no way to use something like this: [!SetVariable LoopEnd ((#LoopEnd#+1)?5:[!PauseMeasure FolderLoopState])] (used in the IfMatchAction2 option of [MeasureOne]). There are two problems with this bang:
  • If you are using the ? conditional operator, before this you have to have a condition. Yes, it's true that (#LoopEnd#+1) can be interpreted as a condition, but in fact it's not quite (however this is the smaller problem).
  • Such a formula has to be entirely numeric. You can't add a bang into it. My supposition is that you want to execute the bang when (#LoopEnd#+1) becomes equal to 5, am I right? But this is not the proper way to achieve this. Just confirm (or deny) this supposition is correct, to show a way to do what you want in a correct form (which works).
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by CodeCode »

balala wrote: December 23rd, 2021, 10:03 pm My supposition is that you want to execute the bang when (#LoopEnd#+1) becomes equal to 5, am I right? But this is not the proper way to achieve this. Just confirm (or deny) this supposition is correct, to show a way to do what you want in a correct form (which works).[/list]
Yes, balala. That is what would be ideal. Since the pause unpause the measure will give the loop a way to end.
If there is a better way to count to 5 just once, in a way that can be utilised like my example, than that is good as well.

But yes. The loop would be going in to manage the Measure that knows when there is an empty string, or an occupied string. If the loop goes through the 5 count then the loop stops until there is another empty string.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by SilverAzide »

CodeCode wrote: December 23rd, 2021, 10:40 pm Yes, balala. That is what would be ideal. Since the pause unpause the measure will give the loop a way to end.
If there is a better way to count to 5 just once, in a way that can be utilised like my example, than that is good as well.

But yes. The loop would be going in to manage the Measure that knows when there is an empty string, or an occupied string. If the loop goes through the 5 count then the loop stops until there is another empty string.
It's not quite clear what you are trying to achieve with the loop, but if you want to loop in a sequence like 1,2,3,1,2,3 etc 5 times, you can do this with modulus math. If the loop end value is X, just loop to a value 5 times X, but use the value % 5 to get the values you want. The numbers will start with 0 however, so add 1... To simplify this, you can use a Calc measure to see the sequence:

Code: Select all

[FolderLoopState]
Measure=Loop
StartValue=0
EndValue=(#LoopEnd# * 5)
Increment=1
LoopCount=1

[CalcLoop]
Measure=Calc
Formula=(FolderLoopState % 5) + 1
I didn't try this, so it might need tweaking, but CalcLoop should produce the sequence you want: 1 to whatever, 5 times then stopping. You don't need the calc measure (just use the formula where needed), so this is just for illustration.
Gadgets Wiki GitHub More Gadgets...
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by CodeCode »

Ok. I understand the loop, and easily allow it to run once and increment up to my desired max value, and that it simply will do it as many times as I need it to with loop count.

The idea is several things are going on with this idea.

A bookmark can be set for up to 5 choices set by the end user.

This happens when a variable is set to an empty string - automatically in tune with the update-=1000

The empty string is then filled to any choice of folder path - chosen by the end user. It happens sequentially e.g if the string is not a default value, the next empty string will be set. This can happen indefinitely if the end user continues to set the variable to empty string.

There is a reset button that sets all shortcut values back to the universal default string - this stops everything until a new path is set and the cycle continues.

There is also a standard refresh - which allows the skin to be reloaded, but the favorites will be preserved.

The issue is that I want to be able to get rid of any of the five variables manually - a right click on a button does this.

What I am trying to avoid is the previous set path variables being overwritten - this happens with an incremental variable that advances when a new path is selected - this is 'aggressive' and will overwrite anything previously saved. Therein lies the nitty gritty. If I test against a non-default value, and all of the strings are occupied, the incremental variable will count 0 to 4 indefinitely, on every update advancing by 1 each time, until forever (i presume anyway).

That is why I need the counter - to go through the list once then stop. I could try a new variable - but that would quintuple my code - or actually I think it could continue, requiring a new variable for every iteration (5 * 5 * 5 ... ?) every time until the math balances on a stable quantification - if one exists with these conditions.
Or I am making this waay too complicated... That is why I ask for help - it is doing my head in. :?
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by SilverAzide »

LOL, yeah, I think you might be wildly overthinking this...
Gadgets Wiki GitHub More Gadgets...
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by CodeCode »

SilverAzide wrote: December 24th, 2021, 4:56 am LOL, yeah, I think you might be wildly overthinking this...
But you get the gist.

How do I prevent the overwrites whist... wait. I just thought of this; set a binary 0 or 1 on the variable at the same time as assignment is made.

That sort (lol) cancels the monstrous stacking variable issue I imagined.

I'll get in to that and I will see before too long if that is a good solution, or not. :bow:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Loop Measure Question = How To Prevent Infinite Loop

Post by CodeCode »

CodeCode wrote: December 24th, 2021, 6:08 am But you get the gist.

How do I prevent the overwrites whist... wait. I just thought of this; set a binary 0 or 1 on the variable at the same time as assignment is made.

That sort (lol) cancels the monstrous stacking variable issue I imagined.

I'll get in to that and I will see before too long if that is a good solution, or not. :bow:
Well - that seems to work great.
I had to add to a total of twenty lines, so not too bad given this makes the whole saving a location more robust.

Man, I so need to start a diary, where is can parse out my ideas and get things into a sensible order. Then, if that doesn't work, ask for help - not the other way around. :lol:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.