It is currently September 26th, 2020, 9:31 pm

Code Reuse and Ifcondition always TRUE

Help with creating, editing & fixing problems with skins
ronzino
Posts: 6
Joined: June 4th, 2020, 4:41 pm

Code Reuse and Ifcondition always TRUE

Post by ronzino »

I wrote a code that I reuse several times in different skin.
So each skin that include this code, has to map/populate the variables and options

this mapping of course as to occur just once, so I wonder which is the best/more elegant and clean way to do this.

At the moment I wrote this

(let's assume that myReuse.inc as a meter called "panelTitle_Meter1", and that myReuse,inc is included in myTest.ini)

Code: Select all

[CPUAvg]
Measure=Calc
Formula=((CPUAvg % 100) + 10)
MinValue=0
MaxValue=100
IfCondition = (1=1)
IfTrueAction=[!SetOption panelTitle_Meter1 Text "[CPUAvg]%"]
IfConditionMode=1
As !Bangs can only occurs under a condition, I am obliged to put an always true condition, and use IfConditionMode=1 to make action at every scan cycle. I think this solution is quite "horrible".....do you have better solution to do this ?

thanks
mak_kawa
Posts: 870
Joined: December 30th, 2015, 9:47 am

Re: Code Reuse and Ifcondition always TRUE

Post by mak_kawa »

Hi ronzino

What about OnUpdateAction=[!SetOption panelTitle_Meter1 Text "[CPUAvg]%"]?

Or...

Code: Select all

[panelTitle_Meter1]
Meter=String
MeasureName=CPUAvg
Text=%1%
User avatar
balala
Rainmeter Sage
Posts: 11415
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Code Reuse and Ifcondition always TRUE

Post by balala »

I don't see why an IfCondition or an OnUpdateAction (as suggested by mak_kawa) would be needed. I simply would add the MeasureName=CPUAvg and the Text=%1% option to the [panelTitle_Meter1] meter and would remove the IfCondition or OnUpdateAction option of the [CPUAvg] measure, exactly as in mak_kawa's second suggestion. Unless I'm missing something, this seems the simplest and best approach.
ronzino
Posts: 6
Joined: June 4th, 2020, 4:41 pm

Re: Code Reuse and Ifcondition always TRUE

Post by ronzino »

balala wrote: July 31st, 2020, 10:23 am ... exactly as in mak_kawa's second suggestion. Unless I'm missing something, this seems the simplest and best approach.
Thankyou guys, yes I have tried and this is the best approach for sure. I had only to add DynamicVariables=1 to reusable sections, as they have relative position and string, which determines the width, is calculated at runtime.

many thanks you both :thumbup: :D
mak_kawa
Posts: 870
Joined: December 30th, 2015, 9:47 am

Re: Code Reuse and Ifcondition always TRUE

Post by mak_kawa »

Hi balala

My first suggestion is a "minimum entropy" solution for ronzino' s original code... just joking, sorry. :-)

Of course, second suggestion is a Rainmeter's standard procedure, as you said.
User avatar
balala
Rainmeter Sage
Posts: 11415
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Code Reuse and Ifcondition always TRUE

Post by balala »

mak_kawa wrote: July 31st, 2020, 10:45 am My first suggestion is a "minimum entropy" solution for ronzino' s original code... just joking, sorry. :-)
No, the first suggestion is alright as well. There is nothing wrong with it.