It is currently March 29th, 2024, 6:37 am

"Flag" variables? How to code something similar in if actions?

Get help with creating, editing & fixing problems with skins
Unatomic
Posts: 33
Joined: October 23rd, 2012, 7:37 pm

"Flag" variables? How to code something similar in if actions?

Post by Unatomic »

Short question: Is there a way to code "flag" variables? Especialy the flag variables need to work inside the "if actions" bang. (Already searched for this but didnt find anything. Please forgive me if there is another post.)

Long question: I am working on a skin to warn the user for big levels (lets say for now) of Ram usage. The problem is that the meter will always execute the same action until the levels of ram usage is lowered.

What i am trying to do is to set a flag variable that will make the "if actions" stop working until the Ram% is lowered way beyond the check point... lets say if the "RecomendedRamUsage" is set to 60, I want to set the meter to start working again when ram% is lower than 40%.

Code: Select all

RecomendedRamUsage=60

[MeasureRAM]
Measure=PhysicalMemory
IfAboveValue=#RecomendedRamUsage#
IfAboveAction=["#CURRENTPATH#PlayIt.exe" "#CURRENTPATH#S.wav"]
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: "Flag" variables? How to code something similar in if actions?

Post by balala »

If I understood well you question, I think you should have to replace the IfAboveValue / IfAboveAction options with IfConditions:

Code: Select all

RecomendedRamUsage=60

[MeasureRAM]
Measure=PhysicalMemory
IfCondition=(#CURRENTSECTION#>#RecomendedRamUsage#)
IfTrueAction=["#CURRENTPATH#PlayIt.exe" "#CURRENTPATH#S.wav"]
IfConditionMode=1
Important in this case is the last option: the IfConditionMode=1, which will execute the IfTrueAction on every updatecycle of the measure.
Unatomic
Posts: 33
Joined: October 23rd, 2012, 7:37 pm

Re: "Flag" variables? How to code something similar in if actions?

Post by Unatomic »

No, it is more like:

Now ram is over 60% so the actions are executed
stop both checking and executing actions until ram is below 40%
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: "Flag" variables? How to code something similar in if actions?

Post by balala »

Let's clarify something, because I'm a bit confused: you'd like to execute the action anytime when the usage is above 60% OR when it's below 40%? And want to not execute it when the usage is between these two values?
Have I understood well?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: "Flag" variables? How to code something similar in if actions?

Post by jsmorley »

Unatomic wrote:No, it is more like:

Now ram is over 60% so the actions are executed
stop both checking and executing actions until ram is below 40%
It doesn't work that way. If it stops checking, how will it ever know that it is below 40%?

The way IfCondition works is that the IfTrueAction is fired once if the test becomes "true". It won't fire that action again until the test becomes "false", and then changes back to "true". The functionality is driven by "becomes true", not "is true".

IfConditionMode=1 overrides this and forces the action to fire every time the test "is true". This should be used with some care. While there are cases where it can be useful, you generally don't want to waste resources doing some action when the result of the test remains the same.

It's simple enough to have actions fired when a value goes over 60% and when a value goes under 40%,. but not when it is between 40%-60%.

Code: Select all

[MeasureCPU]
Measure=CPU
IfCondition=MeasureCPU >60
IfTrueAction=[!Log "Over 60%"]
IfCondition2=MeasureCPU <40
IfTrueAction2=[!Log "Under 40%"]
And again, if you want the actions to be fired every time the test IS true, rather than when it BECOMES true, add IfConditionMode=1 to the measure.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: "Flag" variables? How to code something similar in if actions?

Post by jsmorley »

Extra credit:

If you wanted an action to fire every time when a value IS over 60%, but only once when a value BECOMES under 40%, you could do this:

Code: Select all

[MeasureCPU]
Measure=CPU
IfCondition=MeasureCPU >60
IfTrueAction=[!SetOption MeasureCPU ConditionMode "1"][!Log "Over 60%"]
IfCondition2=MeasureCPU <40
IfTrueAction2=[!SetOption MeasureCPU ConditionMode "0"][!Log "Under 40%"]
Unatomic
Posts: 33
Joined: October 23rd, 2012, 7:37 pm

Re: "Flag" variables? How to code something similar in if actions?

Post by Unatomic »

I know I am not the most descriptive person and sorry about that.The problem I face is that I want to apply the same technique to some temperature skins and a cpu skin that checks cpu load percentage.

And here comes the tricky part. If the persentage is 61% (1% over the recomended usage) it will start "ringing".
THE NEXT SECOND the percentage can be 59% and the skin will reset the IfTrueAction.
THE NEXT SECOND AFTER THAT the percentage can be 62% and it will start "ringing" again!

So it will look like this: 59%(ok) > 61%(ringing) > 59%(ok-reset) > 65%(ringing) > 62%(ok) > 58%(ok-reset) > 63%(ringing) > 59%(ok-reset) > 63%%(ringing) > and so on...

If I described it well enough this time, the skin will ring after 2-3 or 4 seconds if by any luck the recomended percentage or temperature happens to go up and down very near that recomended value.

What I thought was to reset the check ONLY AFTER the recomended percentage or temperatuer drops BY A LOT. And by a lot I mean from 60 to 40 or 50. (ok 40% is a little exaggeration. more like 50%). So it will look like this.

59%(ok) > 61%(ringing) > 59%(ok) > 65%(ringing) > 62%(ok) > 58%(ok-NOT reset) > 63%(OK) > 59%(ok-NOT reset) > 35%(ok-NOW RESET) > 59%(ok) > 63%%(NOW ringing) > and so on...

Now that the problem is set: First of all, my first thought was to use some flag variables to deal with it like some other programing problems. Secondly, should I change the name of the post? Aaaaand that is it.
[hr][/hr]
Let's clarify something, because I'm a bit confused: you'd like to execute the action anytime when the usage is above 60% OR when it's below 40%? And want to not execute it when the usage is between these two values?
Have I understood well?
So I want to execute actions when needed. Execute action when the usage is above 60%, reset when below 40% and not when below 60% and only then start executing actions again when over 60%.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: "Flag" variables? How to code something similar in if actions?

Post by jsmorley »

Yes, you could set a "flag", something like this:

Code: Select all

[Variables]
Reset=1
ResetValue=40
TargetValue=60

[CPU]
Measure=CPU
IfCondition=(CPU >= #TargetValue#) && (#Reset# = 1)
IfTrueAction=[Play "#@#Sounds\Alarm.wav"][!SetVariable Reset "0"]
IfCondition2=CPU <= #ResetValue#
IfTrueAction2=[!SetVariable Reset "1"]
DynamicVariables=1
This feels to me like it might work ok with something like temperatures, which tend to be linear. They progress up and the progress down. It doesn't feel like a good fit for CPU, which is more spiky. That doesn't progress between values, but jumps between them. With CPU, I'd be more inclined to come up with something that says "if the value has stayed at some high level for some period of time, then ring the alarm". Having the CPU spike to a high value for a second or two and then return to a "resting" state is very common.
Unatomic
Posts: 33
Joined: October 23rd, 2012, 7:37 pm

Re: "Flag" variables? How to code something similar in if actions?

Post by Unatomic »

jsmorley wrote:It doesn't feel like a good fit for CPU, which is more spiky. That doesn't progress between values, but jumps between them. With CPU, I'd be more inclined to come up with something that says "if the value has stayed at some high level for some period of time, then ring the alarm". Having the CPU spike to a high value for a second or two and then return to a "resting" state is very common.
You are absolutely right! The general idea was needed to complete the warning technique in order to apply it in other measures. I will work on the flag variables and see if i can get my skin to work like I want. I worked first with ram because you can manipulate it at will. Just open some chrome youtube tabs and it increases... :D !!! But the way you describe a cpu warning should work is very good and I will work on it after completing RAM and temperature warnings.

I will update this post when I finish the flag variables.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: "Flag" variables? How to code something similar in if actions?

Post by jsmorley »

I'd be tempted to at least explore something that averages the CPU over a period of time, and bases the target on the average.

Code: Select all

[Variables]
Reset=1
ResetValue=40
AverageSeconds=10
TargetValue=60

[CPUAvg]
Measure=CPU
AverageSize=#AverageSeconds#
IfCondition=(CPUAvg >= #TargetValue#) && (Reset = 1)
IfTrueAction=[Play "#@#Sounds\Alarm.wav"][!SetVariable Reset "0"]
IfCondition2=CPUAvg <= #ResetValue#
IfTrueAction2=[!SetVariable Reset "1"]
DynamicVariables=1
So that will average the CPU value over a period of 10 seconds, (Update=1000 X 10), really 10 "updates", and will react to that value being over the target. That will smooth out the "spikes".

You would probably want another CPU measure to get the actual real-time value, and maybe display both in some string or bar meter(s).