It is currently September 16th, 2019, 11:30 pm

[Help] Is there a way to get all Meters of a group?

Discuss the use of Lua in Script measures.
Yuuyu
Posts: 1
Joined: July 12th, 2016, 1:37 pm

[Help] Is there a way to get all Meters of a group?

Yuuyu » July 12th, 2016, 2:05 pm

Hello there, I've only just started using Lua to make skins and I'm wondering if there is a method to get each meter of group X and store it into a lua array.

For example:

Code: Select all

[Meter1]
Meter=String
Group=X

[Meter2]
Meter=String
Group=X

[Meter3]
Meter=String
Group=Y
Lua:

Code: Select all

function GetAllOfGroupX()
	GroupXArray = SKIN:GetGroup('X')	-- Note this SKIN method does not exists
	
	return GroupXArray
end

function GetAllOfGroupY()
	GroupYArray = SKIN:GetGroup('Y')	-- Note this SKIN method does not exists
	
	return GroupYArray
end
Output:

Code: Select all

GroupXArray = [Meter1, Meter2]
GroupYArray = [Meter3]
Or is there a way around this?

Thank you! :D
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Help] Is there a way to get all Meters of a group?

jsmorley » July 25th, 2016, 1:15 pm

Not quite sure where you are going with this, but you can read "options" from a skin measure or meter in Lua:

Code: Select all

function Initialize()

	meterTable = {}

	for i = 1, 5 do
		meterTable[i] = SKIN:GetMeter('Meter'..i)
	end
	
end

function Update()

	groupTable = {}
	
	for i = 1, 5 do
		groupTable[i] = meterTable[i]:GetOption('Group', '')
		print('Meter '..i..' is in group '..groupTable[i])
	end

	return 0
		
end

Code: Select all

[Rainmeter]
Update=100
AccurateText=1
DynamicWindowSize=1

[MeasureLua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1

[Meter1]
Meter=String
Group=X
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Meter1

[Meter2]
Meter=String
Group=X
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Meter2

[Meter3]
Meter=String
Group=Y
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Meter3

[Meter4]
Meter=String
Group=X
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Meter4

[Meter5]
Meter=String
Group=Y
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Meter4
1.jpg
What you can't do is "return" an array as a value to the skin. The value of a table in Lua is simply a numeric "handle" to the table / array. You are going to have to have the script either build a single string value that you can return as the value of the script measure, or have it set individual variables, String options on String measures, or Text options on String meters in the skin.
You do not have the required permissions to view the files attached to this post.
User avatar
FreeRaider
Posts: 786
Joined: November 20th, 2012, 11:58 pm

Re: [Help] Is there a way to get all Meters of a group?

FreeRaider » July 27th, 2016, 9:01 am

jsmorley, I have a question:

out of curiosity, in your lua script you use for i = 1, 5 do etc because in your code you call meters with [Meter1], [Meter2], etc , for simplicity.

In a general case, is it possible grab all meters (and to use its numerosity in a "for statement") even if they have literary names (for example: [MeterNow], [MeterTomorrow], [MeterBla], [MeterTemp], etc) ?


Thanks
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Help] Is there a way to get all Meters of a group?

jsmorley » July 27th, 2016, 11:34 am

FreeRaider wrote:jsmorley, I have a question:

out of curiosity, in your lua script you use for i = 1, 5 do etc because in your code you call meters with [Meter1], [Meter2], etc , for simplicity.

In a general case, is it possible grab all meters (and to use its numerosity in a "for statement") even if they have literary names (for example: [MeterNow], [MeterTomorrow], [MeterBla], [MeterTemp], etc) ?


Thanks
Nothing built into our interface between Lua and Rainmeter. You would have write some kind of .ini file "parser" that read the entire file, detected the [Sections] and looked for lines starting with Meter= to determine that it's a meter. Then you could get the section names and create handles that you could use with GetOption.

Something like this might help:

https://docs.rainmeter.net/snippets/read-ini/

Be aware though, that Lua can't read external UTF=16 files, which skin .ini files often are. That will make this a limited solution, and not something with reliable general-purpose use. To be honest, probably more trouble than it's worth... It's really better to either use a numbering scheme like I did, or just hard-code the meter names into the Lua in the Initialize() function to get the meter handles you need.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureScript]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1

[MeterLarry]
Meter=String
Group=X
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Larry

[MeterMoe]
Meter=String
Group=Y
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Moe

[MeterCurlyJoe]
Meter=String
Group=X
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=CurlyJoe

Code: Select all

function Initialize()

	meterArray = {}
	meterArray[1] = SKIN:GetMeter('MeterLarry')
	meterArray[2] = SKIN:GetMeter('MeterMoe')
	meterArray[3] = SKIN:GetMeter('MeterCurlyJoe')
	
end

function Update()

	meterNameArray = {}
	meterGroupArray = {}	
	
	for i = 1, 3 do
		meterNameArray[i] = meterArray[i]:GetName()
		meterGroupArray[i] = meterArray[i]:GetOption('Group')
		print('Meter '..meterNameArray[i]..' is in Group '..meterGroupArray[i])
	end

end
1.jpg
You do not have the required permissions to view the files attached to this post.