I want to make a function that changes color depending on my CPU usage, but I don't want to make multiple functions for each of my CPU cores. Is there a way to pass a variable?
I'm making a Calc Measure btw...
It is currently May 2nd, 2024, 8:09 am
Passing variables to measures...
-
- Posts: 2
- Joined: August 1st, 2012, 10:43 am
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Passing variables to measures...
Not sure I understand what you mean by "changes color". What sort of effect are you going for? You want some meter to be one color when below some value and a different color when above some value?minosu wrote:I want to make a function that changes color depending on my CPU usage, but I don't want to make multiple functions for each of my CPU cores. Is there a way to pass a variable?
I'm making a Calc Measure btw...
As to not dealing with multiple cores, simply use:
[MeasureCPU]
Measure=CPU
Processor=0
That will return a percentage used for your entire CPU.
-
- Posts: 2
- Joined: August 1st, 2012, 10:43 am
Re: Passing variables to measures...
Yes. One colour when below a value and another when above a value.
Simply Measure=CPU gives you all the cores' average CPU usage, too... I wanted to be fancy though~
Hmm... by passing variables I mean something like what Java, BASH or the C's do. When you call a function/method you specify parameters after the name, then you can work with those specific values.
Simply Measure=CPU gives you all the cores' average CPU usage, too... I wanted to be fancy though~
Hmm... by passing variables I mean something like what Java, BASH or the C's do. When you call a function/method you specify parameters after the name, then you can work with those specific values.
Last edited by minosu on August 1st, 2012, 11:04 am, edited 1 time in total.
-
- Rainmeter Sage
- Posts: 889
- Joined: September 6th, 2011, 6:34 am
Re: Passing variables to measures...
The only place where you could really use a function to avoid duplicate code is in a Lua script. Not sure you would need this in this case as it presents additional overhead. In "standard" Rainmeter there is no such thing as functions.
Take a look at IfActions
Take a look at IfActions
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Passing variables to measures...
It would help if you would describe what you have in mind. Did you want it to display each core separately with changing colors or just one meter showing the total / average CPU usage for all cores? I'm just not clear what the question is.minosu wrote:Yes. One colour when below a value and another when above a value.
Simply Measure=CPU gives you all the cores' average CPU usage, too... I wanted to be fancy though~
Having a meter change color based on the value of a measure is not difficult.
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
[MeasureCPU]
Measure=CPU
Processor=0
IfAboveValue=8
IfAboveAction=[!SetOption MeterCPU FontColor 255,0,0,255][!UpdateMeter MeterCPU][!Redraw]
IfBelowValue=9
IfBelowAction=[!SetOption MeterCPU FontColor 0,255,0,255][!UpdateMeter MeterCPU][!Redraw]
[MeterCPU]
Meter=String
MeasureName=MeasureCPU
FontSize=13
FontColor=0,255,0,255
Antialias=1
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Passing variables to measures...
And yes, there really is no way to have a function like MeasureCPU(CPUNum) and then repeatedly call that function is some kind of loop to populate... Well, I'm not even sure to populate what. It is important to understand that Rainmeter is not a procedural language like a bash script or a C program. Rainmeter is a system that at its core does ONE thing. It loads a settings file (.ini) into memory, and runs in a big loop on each Update= value. During that update, it checks each measure to see if it should update them, then updates the meters displaying the results.
If you want to check the value of 4 CPU cores, you need 4 measures, and most likely 4 meters.
It would be easier if you explained what you are trying to end up with as far as the inputs (CPU values) and outputs (what kind of meter display you want) and we can help you get there in the context of how Rainmeter works. Trying to work backwards from (I would code this in some way in C++, how do I do that in Rainmeter?) is probably going to just be the frustrating way to get from A to B.
If you want to check the value of 4 CPU cores, you need 4 measures, and most likely 4 meters.
It would be easier if you explained what you are trying to end up with as far as the inputs (CPU values) and outputs (what kind of meter display you want) and we can help you get there in the context of how Rainmeter works. Trying to work backwards from (I would code this in some way in C++, how do I do that in Rainmeter?) is probably going to just be the frustrating way to get from A to B.