It is currently April 23rd, 2024, 9:19 am

Getting the maximum value of "n" variables

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Getting the maximum value of "n" variables

Post by balala »

jsmorley wrote:Doesn't even have to be "numeric". It will sort strings alphabetically just as easily... Exactly the same Lua function...
Really? Interesting. For a such thing, the lua solution is indeed better, as other solution doesn't even work.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting the maximum value of "n" variables

Post by jsmorley »

I added MinVaue() / MaxValue to the Lua Snippets documentation for future reference.
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: Getting the maximum value of "n" variables

Post by nikko »

how to add a measure instead of variables to get min and max values??? :Whistle
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting the maximum value of "n" variables

Post by jsmorley »

nikko wrote: March 27th, 2021, 2:08 pm how to add a measure instead of variables to get min and max values??? :Whistle
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
Lua:

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

1.png
You do not have the required permissions to view the files attached to this post.
rankin
Posts: 1
Joined: October 6th, 2022, 8:18 am

Re: Getting the maximum value of "n" variables

Post by rankin »

jsmorley wrote: March 27th, 2021, 2:49 pm It's really just the same, only pass it [&MeasureName] section variables instead of #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!