It is currently April 27th, 2024, 11:55 pm

Conditioning in Rainmeter is ambiguous...

Get help with creating, editing & fixing problems with skins
User avatar
Engelard
Posts: 5
Joined: January 31st, 2024, 5:12 pm

Conditioning in Rainmeter is ambiguous...

Post by Engelard »

After four hours of struggling to implement my first(and only necessary) feature which involves some IF's - i have to admit that i failed.

Tell me please why my simple toggle do not working:

Code: Select all

[Variables]
KeyToFront = 0x83
Zval = -2


[Launcher2]
Measure=Plugin
Plugin=HotKey
HotKey=#KeyToFront#
DynamicVariables=1

IfCondition=Zval = 2
IfTrueAction=[!SetVariable Zval "-2"]
IfFalseAction=[!SetVariable Zval "2"]

KeyDownAction=[!ZPos #Zval#][!Redraw]
I mean it works sometimes if swap things around, but only for first keypress, and then it stays even if i refresh skin. This is all so confusing and unintuitive for newbies...
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Conditioning in Rainmeter is ambiguous...

Post by CodeCode »

Try these changes:

Code: Select all

[Variables]
KeyToFront = 0x83
Zval = -2

[Launcher2]
Measure=Plugin
Plugin=HotKey
HotKey=#KeyToFront#
DynamicVariables=1

IfCondition=Zval = 2
IfTrueAction=[!SetVariable Zval "-2"][!Update]
IfFalseAction=[!SetVariable Zval "2"][!Update]
DynamicVariables=1

KeyDownAction=[!ZPos #Zval#][!Redraw]
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
Engelard
Posts: 5
Joined: January 31st, 2024, 5:12 pm

Re: Conditioning in Rainmeter is ambiguous...

Post by Engelard »

CodeCode wrote: January 31st, 2024, 5:57 pm Try these changes:
I tried such stuff before i created this topic. Does nothing.

It only works if initial Zval(in [Variables]) is same as in IF condition.
So it you change to Zval = 2 it will work but as i said only once, with first keypress.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Conditioning in Rainmeter is ambiguous...

Post by balala »

Engelard wrote: January 31st, 2024, 5:23 pm Tell me please why my simple toggle do not working:
Because the IfCondition is little bit wrong. Zval means not too much in Rainmeter terminology, it is just the name of the variable, not its value. What you should have to do is to use its value in the IfCondition option, this way: IfCondition=#Zval# = 2. What is extremely important here are the red-colored # characters. By adding them, you tell Rainmeter that Zval is a variable and its value has to be compared by 2.
User avatar
Engelard
Posts: 5
Joined: January 31st, 2024, 5:12 pm

Re: Conditioning in Rainmeter is ambiguous...

Post by Engelard »

I know what ## are, i used it alot. But in all examples of Conditions nobody used it, so i followed examples. Tried to add ## you proposed, Rainmeter crashed ;-)
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Conditioning in Rainmeter is ambiguous...

Post by balala »

Engelard wrote: January 31st, 2024, 7:36 pm I know what ## are, i used it alot. But in all examples of Conditions nobody used it, so i followed examples.
You shouldn't have to add those # characters, if Zval were a measure. But it's a variable (it is posted into the [Variables] section). As such, we're referring to its value by including its name into # characters. If you take a look to the log when these characters are not added, on refresh of the skin, you get the following error:
"Zval" is unknown: IfCondition=Zval = 2
This means Rainmeter didn't recognize Zval, didn't realize it is a variable. This is fixed by adding the # characters.
Engelard wrote: January 31st, 2024, 7:36 pm Tried to add ## you proposed, Rainmeter crashed ;-)
I tried the posted code (both with and without the # characters), but didn't crash Rainmeter. I assume your code is larger / longer than what have you posted. Please post the whole code to can take a look what is causing the crash.
User avatar
Engelard
Posts: 5
Joined: January 31st, 2024, 5:12 pm

Re: Conditioning in Rainmeter is ambiguous...

Post by Engelard »

balala wrote: January 31st, 2024, 7:51 pm This means Rainmeter didn't recognize Zval, didn't realize it is a variable. This is fixed by adding the # characters.
Wow, now i get it, thanks.

Code is really larger, but i don't really touch any of it, mostly play with that section i posted here.
Skin i'm dealing with - is popular SK Neon Meters, which i'm modify bit by bit(only fourth version that called Meters.ini)
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Conditioning in Rainmeter is ambiguous...

Post by balala »

Engelard wrote: January 31st, 2024, 8:12 pm Wow, now i get it, thanks.
Right, now I see what is going wrong, but I should have been realizing this even with the posted piece of code. Sorry, my bad!
What is a problem in your code is an infinite loop, created by the IfCondition, when it is written correctly. When refreshing the skin the value of the Zval variable is set to -2. Accordingly the IfCondition is false, so IfFalseAction is immediately executed. Its !SetVariable bang sets the value of the Zval variable to 2. Changing this way the value of the variable, the IfCondition is reevaluated on next update of the skin (so after a second, due to the Update=1000 option of the [Rainmeter] section). But this time the condition is meet, so IfTrueAction is executed. This sets the value of the variable back to -2. This process goes on infinitely, crashing finally Rainmeter. Absolutely normal behavior.
The IfCondition in this form makes not too much sense. What do you want to achieve, because I1m not sure I can follow. A first and extremely simple solution is to add an UpdateDivider=-1 option to the [Launcher2] measure, which contains the IfCondition, to avoid its continuous update, but as said, doesn't really make sense in my opinion.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Conditioning in Rainmeter is ambiguous...

Post by eclectic-tech »

Engelard wrote: January 31st, 2024, 5:23 pm After four hours of struggling to implement my first(and only necessary) feature which involves some IF's - i have to admit that i failed.

Tell me please why my simple toggle do not working:

Code: Select all

[Variables]
KeyToFront = 0x83
Zval = -2


[Launcher2]
Measure=Plugin
Plugin=HotKey
HotKey=#KeyToFront#
DynamicVariables=1

IfCondition=Zval = 2
IfTrueAction=[!SetVariable Zval "-2"]
IfFalseAction=[!SetVariable Zval "2"]

KeyDownAction=[!ZPos #Zval#][!Redraw]
I mean it works sometimes if swap things around, but only for first keypress, and then it stays even if i refresh skin. This is all so confusing and unintuitive for newbies...
As mentioned by balala, your IfCondition continually change the variable from -2 to 2 in a continuous loop.

It appears you want to change the Z-position of the skin using the variable #ZVal#.

If that is correct, then I would suggest moving the IfCondition to a separate Calc measure that is not updated by the skin's update rate.
Set that measure to never update after loading by setting the UpdateDivider on that measure to UpdateDivider=-1.

This example will change the z-position of a 100x100 square meter each time the F12 key is pressed (I don't have a F20 key; 0x83).

Code: Select all

[Variables]
; F20 Key? I use F12 (0x7B)
KeyToFront = 0x7B
Zval = -2


[Launcher2]
Measure=Plugin
Plugin=HotKey
HotKey=#KeyToFront#
KeyDownAction=[!UpdateMeasure Status]

[Status]
Measure=Calc
Formula=#Zval#
IfCondition=#Zval#=2
IfTrueAction=[!SetVariable Zval "-2"][!ZPos "[#Zval]"][!Redraw]
IfFalseAction=[!SetVariable Zval "2"][!ZPos "[#Zval]"][!Redraw]
UpdateDivider=-1
DynamicVariables=1

[MeterImage]
Meter=Image
ImageName=
X=0
Y=0
W=100
H=100
SolidColor=0,0,0,100
Because I want to use the newly set #ZVal# in the same string of bangs to redraw the skin, I have to use the nested version in the !ZPos bang; [!ZPos "[#ZVal]"].
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Conditioning in Rainmeter is ambiguous...

Post by balala »

Engelard wrote: January 31st, 2024, 7:36 pm Tried to add ## you proposed, Rainmeter crashed ;-)
In meantime reading eclectic-tech's reply, I think I realized what is your intention. Besides eclectic-tech's good advice, there might be another solution as well. If you want to try out this as well, you can try adding the UpdateDivider=-1 option to the [Launcher2] measure (as explained previously) and add a [!UpdateMeasure "Launcher2"] bang to the KeyDownAction option of the same [Launcher2] measure as well: KeyDownAction=[!ZPos #Zval#][!UpdateMeasure "Launcher2"][!Redraw]. This way when you hit the key, the position of the skin is set and the measure is updated, which leds on changing the value of the variable.
Please let us know if any of these two solutions meats your needs.