It is currently April 24th, 2024, 7:23 am

How do I make Rainmeter interpret a string as a number?

Get help with creating, editing & fixing problems with skins
GordenFreemant
Posts: 9
Joined: March 5th, 2016, 7:53 pm

How do I make Rainmeter interpret a string as a number?

Post by GordenFreemant »

I'm trying to build a simple small skin that uses Core Temp to display CPU temperature as a histogram and a horizontal line that tracks the last histogram value's Y position. This would probably be easy if the "TjMax" metric returned a value, which it doesn't, because my CPU doesn't expose that value. Core Temp instead returns zero. I circumvented that problem with a quick Substitute:

Code: Select all

[measureCPUTjMax]
 Measure=Plugin
 Plugin=CoreTemp
 CoreTempType=TjMax
 Substitute="0":"#CPUTempMaxFallback#"
CPUTempMaxFallback is defined in my Variables.inc like this:

Code: Select all

CPUTempMaxFallback=95
Image

The problem I now face is that Rainmeter interprets this value as both a string with the value "95" and a number with the value 0, making it all but useless in formulas or for any purpose where numbers should be used (such as the MaxValue part of a histogram).
Is there a way to force Rainmeter to parse the string value as a number? If there isn't, how do I get this to work the way I want it to?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How do I make Rainmeter interpret a string as a number?

Post by jsmorley »

Code: Select all

[measureCPUTjMax]
Measure=Plugin
Plugin=CoreTemp
CoreTempType=TjMax
Substitute="0":"#CPUTempMaxFallback#"
 
[MeasureMakeNum]
Measure=Calc
Formula=[measureCPUTjMax]
DynamicVariables=1

1.png


https://docs.rainmeter.net/manual/variables/section-variables/

Basically, anywhere you use a measure value as a [SectionVariable] it will use the string value of the measure, unless you use [SectionVariable:] which will force it to use the number value. In the context of a Calc measure, this will set both the number and string value of the Calc measure to the string value of the referenced measure. Be sure to use DynamicVariables=1 anywhere you use a section variable.

Depending on where you want to use this number value, you may well not need a separate Calc measure, but simply use the [SectionVariable] and DyanmicVariables=1 where you want to treat the string value of the measure as a number. Just keep in mind however that you can't use a [SectionVariable] as a MeasureName option to bind a measure to a meter, so in that case the Calc measure would be the best route.

[MeterBar]
Meter=Bar
MeasureName=measureCPUTjMax
Nope: this will use the zero numeric value

[MeterBar]
Meter=Bar
MeasureName=[measureCPUTjMax]
DyanmicVariables=1
Nope: this is invalid

[MeterBar]
Meter=Bar
MeasureName=MeasureMakeNum
Yep...
You do not have the required permissions to view the files attached to this post.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: How do I make Rainmeter interpret a string as a number?

Post by mak_kawa »

Curious... my CoreTemp and its plugin grab both numeric and string values. What is the difference??
Untitled-1.png
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How do I make Rainmeter interpret a string as a number?

Post by jsmorley »

mak_kawa wrote: January 3rd, 2020, 3:50 am Curious... my CoreTemp and its plugin grab both numeric and string values. What is the difference??
Untitled-1.png
As the original poster suggested, his particular system doesn't support that value.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: How do I make Rainmeter interpret a string as a number?

Post by mak_kawa »

Thanks... my failure, again.