It is currently April 13th, 2021, 9:52 am

Getting the maximum value of "n" variables

Help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 12545
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: 21617
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: 40
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: 21617
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.