It is currently September 9th, 2024, 11:31 am

[Quirk] IfCondition=0 or 1

Report bugs with the Rainmeter application and suggest features.
User avatar
killall-q
Posts: 307
Joined: August 14th, 2009, 8:04 am

[Quirk] IfCondition=0 or 1

Post by killall-q »

I used IfCondition incorrectly, as if it was IfAboveValue/IfBelowValue/etc, and discovered a quirk.

Code: Select all

[mZero] ;Always returns false
Measure=Calc
IfCondition=0
IfTrueAction=!Log "0 True"
IfFalseAction=!Log "0 False"

[mOne] ;Always returns true
Measure=Calc
IfCondition=1
IfTrueAction=!Log "1 True"
IfFalseAction=!Log "1 False"
These actions trigger on skin load/refresh. It does not matter what the value of the measure is. If IfConditionMode=1, they will trigger every update. Only the values 0 and 1 cause an action to be triggered.

This quirk makes sense considering that 0 == false and 1 == true in C.
User avatar
KazukiGames82
Posts: 32
Joined: January 25th, 2023, 2:56 am

Re: [Quirk] IfCondition=0 or 1

Post by KazukiGames82 »

killall-q wrote: August 22nd, 2024, 10:08 pm This quirk makes sense considering that 0 == false and 1 == true in C.
i guess this line do that.
https://github.com/rainmeter/rainmeter/blob/18cfcfd2a77238efe4d039013bfff6fdc33291f1/Library/IfActions.cpp#L225
but you should use properly IfCondition=.
User avatar
Yincognito
Rainmeter Sage
Posts: 8050
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [Quirk] IfCondition=0 or 1

Post by Yincognito »

killall-q wrote: August 22nd, 2024, 10:08 pm I used IfCondition incorrectly, as if it was IfAboveValue/IfBelowValue/etc, and discovered a quirk.
[...]
These actions trigger on skin load/refresh. It does not matter what the value of the measure is. If IfConditionMode=1, they will trigger every update. Only the values 0 and 1 cause an action to be triggered.

This quirk makes sense considering that 0 == false and 1 == true in C.
If I'm understanding this properly, the quirk is known already and mainly used in testing or other non orthodox scenarios where you want the actions to either never or always execute, with IfConditionMode controlling whether that happens just once or on every update. :???:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16506
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [Quirk] IfCondition=0 or 1

Post by balala »

killall-q wrote: August 22nd, 2024, 10:08 pm These actions trigger on skin load/refresh. It does not matter what the value of the measure is. If IfConditionMode=1, they will trigger every update. Only the values 0 and 1 cause an action to be triggered.
In logical conditions 0 always means false, while 1 always means true. This is why the IfCondition=0 option of the [mZero] measure is always false and the IfCondition=1 option of the [mOne] measure is always true. Logically these options are completely correct, however they make not too mucj sense. Unlike in IfActions, in the IfCondition option you can use a real condition, not just a value. What I assume you should have to use is something like this: IfCondition=(mZero=0), for instance.

Additional tip: In Rainmeter, unlike in a programming language, the comments always have to go to new line. Don't add those comments after any kind of option, neither after a section name, nor after an option. Rainmeter simply doesn't ignore these comments, the semicolon being treated like a commenting out character ONLY if it is the first character on a line. So, strictly speaking the above code should look like this:

Code: Select all

[mZero]
;Always returns false
...

[mOne]
;Always returns true
...