It is currently April 19th, 2024, 6:14 pm

[solved] Having Trouble With Variables Being Used To Write To Another Variable

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

[solved] Having Trouble With Variables Being Used To Write To Another Variable

Post by CodeCode »

Hello.
I am tinkering with my FileView skin.
I am writing to a variable, like this:

Code: Select all

Meter=String
RightMouseUpAction=[!SetClip [mPath]][!SetVariable FaveSet [mPath]][!WriteKeyValue Variables FaveSet [mPath] "#@#TitanVars.inc"][!Update *]
It works fine.
But I am trying to get that variable and write it to another variable for future use, so WriteKeyValue and SetVariable are necessary.
I am having trouble with managing the Write to that variable.
I am trying a Measure to handle the variable and two more, as part of a set of buttons that appear when the above line is written., but I am not getting results.
The idea is to get the FaveSet and write it to the first store variable that has an empty string for its value.
I have a set of lines I think should be part of the goal: I know that the IfCondition wont work, I just put it there so the idea could be exemplified below...

Code: Select all

[mFavourite]
Measure=Calc
IfCondition=(#FaveOne# = "")
IfTrueAction=[!SetVariable FaveOne """#FaveSet#"""][!WriteKeyValue Variables FaveOne """#FaveSet#""" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfFalseAction=[!CommandMeasure mFavourite "Update"]
IfCondition2=(#FaveTwo# = "")
IfTrueAction2=[!SetVariable FaveTwo """#FaveSet#"""][!WriteKeyValue Variables FaveTwo """#FaveSet#""" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfFalseAction2=[!CommandMeasure mFavourite "Update"]
IfCondition3=(#FaveThree# = "")
IfTrueAction3=[!SetVariable FaveThree """#FaveSet#"""][!WriteKeyValue Variables FaveThree """#FaveSet#""" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfFalseAction3=[!CommandMeasure mFavourite "Update"]
OnChangeAction=[!Update *]
I hope that makes some sense. Even if it is in the wrong form.
Recap:
If #FaveOne# is empty string write the value of #FaveSet# to #FaveOne# . If not empty try to set to #FaveTwo#. If not empty again try to set to #FaveThree#. If not empty string at this point; do nothing (for now anyway).

Thanks for any help.
Last edited by CodeCode on December 19th, 2021, 1:53 pm, edited 1 time in total.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by CodeCode »

Ok. So I tried this way, but it doesn't work.

So, just updating my progress, or lack thereof.

Code: Select all

[mFavourite1]
Measure=Calc
Formula=#FaveOne#
IfMatch=""
IfMatchAction=[!SetVariable "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"][!WriteKeyValue Variables "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeasure mFavourite2]

[mFavourite2]
Measure=Calc
Formula=#FaveTwo#
IfMatch=""
IfMatchAction=[!SetVariable FaveTwo #FaveSet# "#@#TitanVars.inc"][!WriteKeyValue Variables FaveTwo #FaveSet# "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeasure mFavourite3]

[mFavourite3]
Measure=Calc
Formula=#FaveThree#
IfMatch=""
IfMatchAction=[!SetVariable FaveThree #FaveSet# "#@#TitanVars.inc"][!WriteKeyValue Variables FaveThree #FaveSet# "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by death.crafter »

CodeCode wrote: December 13th, 2021, 4:18 am Ok. So I tried this way, but it doesn't work.

So, just updating my progress, or lack thereof.

Code: Select all

[mFavourite1]
Measure=Calc
Formula=#FaveOne#
IfMatch=""
IfMatchAction=[!SetVariable "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"][!WriteKeyValue Variables "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeasure mFavourite2]

[mFavourite2]
Measure=Calc
Formula=#FaveTwo#
IfMatch=""
IfMatchAction=[!SetVariable FaveTwo #FaveSet# "#@#TitanVars.inc"][!WriteKeyValue Variables FaveTwo #FaveSet# "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeasure mFavourite3]

[mFavourite3]
Measure=Calc
Formula=#FaveThree#
IfMatch=""
IfMatchAction=[!SetVariable FaveThree #FaveSet# "#@#TitanVars.inc"][!WriteKeyValue Variables FaveThree #FaveSet# "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeasureGroup Children][!UpdateMeter *]
You use a String measure and not a calc.
from the Realm of Death
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by balala »

CodeCode wrote: December 13th, 2021, 1:35 am I hope that makes some sense. Even if it is in the wrong form.
Beside what death.crafter said (and he is perfectly right), there are more problems in both your codes:
  • You can't check with IfCondition if a variable is empty. IfConditions have to be entirely numeric. They can't check string matching. For such a thing you have to use IfMatch. But for checking three variables, you probably will need three String measures, with one IfMatch option set in each. I suppose you figured this out in meantime.
    CodeCode wrote: December 13th, 2021, 4:18 am Ok. So I tried this way, but it doesn't work.
  • The above !SetVariable bangs have a wrong form: their last parameter (if they have such a parameter) has to be a config, not a file. For instance in the [!SetVariable "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"] bang (the first bang of the IfMatchAction option of the [mFavourite1] measure) doesn't work. It can't set the variable into the #@#TitanVars.inc file. Instead it has to set the variable into a config. Something like [!SetVariable "FaveOne" "#FaveSet#" "MyConfig"], where MyConfig has to be the name of the config in which the variable are used. Just as a side note the meters and/or measures which there have to use the variable, have to have set the DynamicVariables=1 option (but this is another story).
  • In the above mentioned bang, there is an extra quote: [!SetVariable "FaveOne" "#FaveSet#"" "#@#TitanVars.inc"]. Even if this is a typo (which I believe, because there is no such quote in the other bangs), it has to be removed (besides replacing the file with a config, as described above).
There are other issues as well, but first these are the most important ones.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by CodeCode »

Thanks for those debugging tips.

After that I am trying this:

Code: Select all

[mFavourite1]
Measure=String
String=#FaveOne#
IfMatch=""
IfMatchAction=[!SetVariable FaveOne "#FaveSet#"][!WriteKeyValue Variables "FaveOne" "#FaveSet#" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeter MeterOne]
DynamicVariables=1
But it isn't going. I am missing something. I just cannot remember what it is. I usually look through my other projects for help, but this is kind of a new thing - or it seems that way, but isn't (or is?).
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by death.crafter »

CodeCode wrote: December 13th, 2021, 9:13 am Thanks for those debugging tips.

After that I am trying this:

Code: Select all

[mFavourite1]
Measure=String
String=#FaveOne#
IfMatch=""
IfMatchAction=[!SetVariable FaveOne "#FaveSet#"][!WriteKeyValue Variables "FaveOne" "#FaveSet#" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeter MeterOne]
DynamicVariables=1
But it isn't going. I am missing something. I just cannot remember what it is. I usually look through my other projects for help, but this is kind of a new thing - or it seems that way, but isn't (or is?).
It's pretty unclear as to what you want to do and what isn't working as you expect it to. Please be more verbose, as the code above should work fine by itself.
from the Realm of Death
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by ikarus1969 »

If you want to check if a variable is empty within a string-meter as you have coded you have to write:
IfMatch=^$

which means no characters at all between the beginning (marked with the ^) and the end (marked with the $)

so something similar to:

Code: Select all

[mFavourite1]
Measure=String
String=#FaveOne#
IfMatch=^$
IfMatchAction=[!SetVariable FaveOne "#FaveSet#"][!WriteKeyValue Variables "FaveOne" "#FaveSet#" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeter MeterOne]
DynamicVariables=1
Last edited by ikarus1969 on December 13th, 2021, 12:50 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by jsmorley »

ikarus1969 wrote: December 13th, 2021, 12:49 pm If you want to check if a variable is empty within a string-meter as you have coded you have to write:
IfMatch=^$

which means no characters at all between the beginning (marked with the ^) and the end (marked with the $)
Correct. Regular Expression has no concept of "" or NULL string in it.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by CodeCode »

ikarus1969 wrote: December 13th, 2021, 12:49 pm If you want to check if a variable is empty within a string-meter as you have coded you have to write:
IfMatch=^$

which means no characters at all between the beginning (marked with the ^) and the end (marked with the $)

so something similar to:

Code: Select all

[mFavourite1]
Measure=String
String=#FaveOne#
IfMatch=^$
IfMatchAction=[!SetVariable FaveOne "#FaveSet#"][!WriteKeyValue Variables "FaveOne" "#FaveSet#" "#@#TitanVars.inc"][!UpdateMeasure mPath][!UpdateMeter *]
IfNotMatchAction=[!UpdateMeter MeterOne]
DynamicVariables=1
Yes. I adapted to this, but have not updated this thread yet.
So I have a working method. Problem is, the skin needs to be refreshed - twice. Once to have the skin 'see' the new value, then again to set the FaveOne value to that same value.
This is what I am using at the moment:

Code: Select all

[mFavourite1]
Measure=String
String=[#FaveOne]
IfMatch=^$
IfMatchAction=[!SetVariable FaveOne [#FaveSet]][!WriteKeyValue Variables FaveOne [#FaveSet] "#@#TitanVars.inc"][!UpdateMeter MeterOne]
IfNotMatchAction=[!UpdateMeasure "mFavourite2"]
DynamicVariables=1

[mFavourite2]
Measure=String
String=[#FaveTwo]
IfMatch=^$
IfMatchAction=[!SetVariable FaveTwo [#FaveSet]][!WriteKeyValue Variables FaveTwo [#FaveSet] "#@#TitanVars.inc"][!UpdateMeter MeterOne]
IfNotMatchAction=[!UpdateMeasure "mFavourite3"]
DynamicVariables=1

[mFavourite3]
Measure=String
String=[#FaveThree]
IfMatch=^$
IfMatchAction=[!SetVariable FaveThree [#FaveSet]][!WriteKeyValue Variables FaveThree [#FaveSet] "#@#TitanVars.inc"][!UpdateMeter MeterOne]
IfNotMatchAction=[!Update]
DynamicVariables=1
death.crafter wrote: December 13th, 2021, 12:30 pm It's pretty unclear as to what you want to do and what isn't working as you expect it to. Please be more verbose, as the code above should work fine by itself.
I explained my intentions here: https://forum.rainmeter.net/viewtopic.php?t=39235#p201562 with this;
If #FaveOne# is empty string write the value of #FaveSet# to #FaveOne# . If not empty try to set to #FaveTwo#. If not empty again try to set to #FaveThree#. If not empty string at this point; do nothing (for now anyway).
The problem with my current (as of this post) method, is for some reason, the mFavourite1, mFavourite2, mFavourite3 all update to the set path. I know it is because as soon as the FaveOne variable is not empty somehow immediately so all three Fave... variables are being set.

I am beginning to think this idea is not possible in as much as requiring repeated Refreshes to actually work - which short circuits the fall through logic I am trying to use.

Really feeling crazy since this is so messy, and seems to be a loop-trap idea... O.O
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1365
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Having Trouble With Variables Being Used To Write To Another Variable

Post by CodeCode »

This is the trigger for the whole shebang:

Code: Select all

[Path]
Meter=String
MeasureName=mPath
Text="%1"
RightMouseUpAction=[!SetClip [mPath]][!SetVariable FaveSet [mPath]][!WriteKeyValue Variables FaveSet [mPath] "#@#TitanVars.inc"][!!CommandMeasure "mFavourite" "Update"][!Update *]
DynamicVariables=1
This is my button meter. This button will actually follow the path.
The path is supposed to be a "favourite" and one of three possible favourites.

Code: Select all

[MeterOne]
Meter=Image
ImageName=#@#1.png
ImageTint=#MainColor#
X=180
Y=24
W=40
H=40
LeftMouseUpAction=[!SetOption mPath "Path" """#FaveOne#"""][!CommandMeasure mPath "FollowPath"][!UpdateMeasure mPath][!CommandMeasure mPath "Update"][!UpdateMeasureGroup Children][!UpdateMeter *][!Redraw]
RightMouseUpAction=[!SetVariable FaveOne """"""][!WriteKeyValue Variables FaveOne """""" "#@#TitanVars.inc"][!SetOption mPath "Path" """"""][!UpdateMeter *][!Redraw]
DynamicVariables=1
AntiAlias=1
Hidden=0
If there is actually a way this can work. Eventually the buttons will only appear once they have a set value.
But again I think this is really not a job for only rainmeter script. I feel certain lua could do it. So I think I might abandon the idea, under the premise that someone who does know lua would have to write that code for me, and I am not really expecting that - aT ALL.

So, I think I will take a few more jabs at this, but if it simply is too sloppy - I'll just dump the idea. :Whistle
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.