Really? Interesting. For a such thing, the lua solution is indeed better, as other solution doesn't even work.jsmorley wrote:Doesn't even have to be "numeric". It will sort strings alphabetically just as easily... Exactly the same Lua function...
It is currently March 23rd, 2023, 7:47 pm
Getting the maximum value of "n" variables
-
- Rainmeter Sage
- Posts: 15058
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Getting the maximum value of "n" variables
-
- Developer
- Posts: 22564
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting the maximum value of "n" variables
I added MinVaue() / MaxValue to the Lua Snippets documentation for future reference.
-
- Posts: 44
- Joined: December 5th, 2017, 5:58 pm
Re: Getting the maximum value of "n" variables
how to add a measure instead of variables to get min and max values??? 

-
- Developer
- Posts: 22564
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting the maximum value of "n" variables
It's really just the same, only pass it [&MeasureName] section variables instead of #Variables#.
Skin:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[Variables]
Var1=2
Var2=15
Var3=10
Var4=7
[MeasureValue1]
Measure=Calc
Formula=2
[MeasureValue2]
Measure=Calc
Formula=15
[MeasureValue3]
Measure=Calc
Formula=10
[MeasureValue4]
Measure=Calc
Formula=7
[Lua]
Measure=Script
ScriptFile=LuaMinMax.lua
UpdateDivider=-1
[MeterMax]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Maximum Variable Value is: [&Lua:MaxValue(#Var1#, #Var2#, #Var3#, #Var4#)]
DynamicVariables=1
[MeterMin]
Meter=String
Y=5R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Minimum Measure Value is: [&Lua:MinValue([&MeasureValue1], [&MeasureValue2], [&MeasureValue3], [&MeasureValue4])]
DynamicVariables=1
Code: Select all
function MinValue(...)
valueTable = {}
for i = 1, #arg do
table.insert(valueTable, arg[i])
end
table.sort(valueTable, function(a,b) return a<b end)
return valueTable[1]
end
function MaxValue(...)
valueTable = {}
for i = 1, #arg do
table.insert(valueTable, arg[i])
end
table.sort(valueTable, function(a,b) return a>b end)
return valueTable[1]
end
You do not have the required permissions to view the files attached to this post.
-
- Posts: 1
- Joined: October 6th, 2022, 8:18 am
Re: Getting the maximum value of "n" variables
Thank you very much for this solution. Was was desperatly looking for some possibility to show the highest of all core clocks on a meter. My script reads each core's clocks with hwinfo and returns the highest one with lua now. This works!