It is currently November 19th, 2018, 8:13 am

Lua for me.

Discuss the use of Lua in Script measures.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Lua for me.

kyriakos876 » September 27th, 2018, 3:03 pm

I'm naming this thread this was so I can ask things about lua in one post and so that I can easily find them when I forget something. I hate having to ask the same thing more than once just because I don't remember how or when I asked the question. Anyway,

So my first question on this thread is as follows:

Code: Select all

	local example = "an example string"
	for i in string.gmatch(example, "%S+") do
		print(i)
	end
I found this piece of code that splits the string into words. I want to split it into individual letters, what would I change so that I can get a b c out of an abc string?

EDIT: I tried really hard to understand how to do it from here http://lua-users.org/wiki/SplitJoin but boy is it hard to understand anything from this page...
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 27th, 2018, 3:21 pm

For example:

Code: Select all

	local example = "an example string"
	for i in string.gmatch(example, ".") do
		print(i)
	end
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 27th, 2018, 3:30 pm

balala wrote:For example:

Code: Select all

	local example = "an example string"
	for i in string.gmatch(example, ".") do
		print(i)
	end
Well I'd be damned... I'd swear I tried this before and it didn't work... why does it work now??

Meeh I don't understand. Anyway, that works now so thanks!!
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 27th, 2018, 3:54 pm

kyriakos876 wrote:Well I'd be damned... I'd swear I tried this before and it didn't work... why does it work now??
I don't know, but probably there was a small mistake. I suppose...
However, I'm glad to help.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 27th, 2018, 3:56 pm

balala wrote:I don't know, but probably there was a small mistake. I suppose...
However, I'm glad to help.
You're probably right...

Do you maybe know also why does this not work

Code: Select all

	SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Drive" "%s:" "#@#FileToEdit.txt"',i))
but this works?

Code: Select all

	SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Drive" "C:" "#@#FileToEdit.txt"',i))
if you look closely I changed the "%s:" to "C:", can I not have 2 variables in one bang or something? Why does the first one throw Script: Lua.lua:14: bad argument #3 to 'format' (no value) on the log?
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 27th, 2018, 4:47 pm

ah I found out I only had to add another ,i so now it works

Code: Select all

  SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Drive" "%s:" "#@#FileToEdit.txt"',i,i))
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 27th, 2018, 5:11 pm

kyriakos876 wrote:ah I found out I only had to add another ,i so now it works

Code: Select all

  SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Drive" "%s:" "#@#FileToEdit.txt"',i,i))
Could you please post the whole lua code?
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 27th, 2018, 5:46 pm

balala wrote:Could you please post the whole lua code?
Well, you asked for it... my issue now is that I cannot figure how to escape some characters to write some stuff.... for example in line 32, it writes on the destined file only IconAnimationIn=[!SetVariable Underliner_Width_C (Clamp(0+25,0,(240-[MeterDiskC_Name:X]*2)))][!UpdateMeter Underliner_C][!UpdateMeasure ][!Redraw]

without the actual [!UpdateMeasure ] argument which should be the name of the measure.
This happens for most of the bang that have the caracters # or double quotes inside of double quotes... and it's a mess in general... I'll figure it out eventually.

If you see line 68, I managed to make the bang get written correctly by escaping the brackets like that:
"\[%s:\\]"

Code: Select all

function Update()

	AllDisksLua = SKIN:GetVariable('AllDisks')
	NumOfLetters = string.len(AllDisksLua)

end

function Split()
	
	for i in string.gmatch(AllDisksLua, "%a") do
	
		--Variable creation
		SKIN:Bang(string.format('!WriteKeyValue Variables "Underliner_Width_%s" "0" "#@#Variables.inc"',i))
		
		--Measure creation
		SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Measure" "FreeDiskSpace" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Drive" "%s:" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "Total" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureTotalDisk%s "UpdateDivider" "100" "#@#FileToEdit.txt"',i))
		--%s????????????
		
		SKIN:Bang(string.format('!WriteKeyValue MeasureUsedDisk%s "Measure" "FreeDiskSpace" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureUsedDisk%s "Drive" "%s:" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureUsedDisk%s "InvertMeasure" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeasureUsedDisk%s "UpdateDivider" "100" "#@#FileToEdit.txt"',i))
	

		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "Measure" "Plugin" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "Plugin" "ActionTimer" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "ActionList1" "UpdateOnce | Wait 16 | Repeat IconAnimationIn, 16, 16" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "UpdateOnce" "[!Update]" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "IconAnimationIn" "[!SetVariable Underliner_Width_%s (Clamp(#Underliner_Width_%s#+25,0,(#MaxWidth#-[MeterDisk%s_Name:X]*2)))][!UpdateMeter Underliner_%s][!UpdateMeasure #CurrentSection#][!Redraw]" "#@#FileToEdit.txt"',i,i,i,i,i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "ActionList2" "UpdateOnce | Wait 25 | Repeat IconAnimationOut, 16, 13" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "IconAnimationOut" "[!SetVariable Underliner_Width_%s (Clamp(#Underliner_Width_%s#-20,0,(#MaxWidth#-[MeterDisk%s_Name:X]*2)))][!UpdateMeter Underliner_%s][!UpdateMeasure #CurrentSection#][!Redraw]" "#@#FileToEdit.txt"',i,i,i,i,i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "ActionList3" "UpdateOnce | Wait 25 | Repeat MouseUp, 16, 6" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue DiskAnimation%s "MouseUp" "[!SetVariable Underliner_Width_%s (Clamp(#Underliner_Width_%s#-20,130,(#MaxWidth#-[MeterDisk%s_Name:X]*2)))][!UpdateMeter Underliner_%s][!UpdateMeasure #CurrentSection#][!Redraw]" "#@#FileToEdit.txt"',i,i,i,i,i))
		
		--print(i)
		
		--Meter creation
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "Meter" "String" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "MeterStyle" "NormalLeft" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "X" "#XFromTheWall#" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "Y" "20r" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "Text" ""%s:\"" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "DynamicVariables" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Name "UpdateDivider" "-1" "#@#FileToEdit.txt"',i))
		
		
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "Meter" "String" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "MeasureName" "MeasureUsedDisk%s" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "MeasureName2" "MeasureTotalDisk%s" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "MeterStyle" "NormalRight" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "X" "(#MaxWidth#-#XFromTheWall#)" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "Y" "r" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "Text" "%%1B/%%2B" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "NumOfDecimals" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "AutoScale" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue MeterDisk%s_Value "UpdateDivider" "100" "#@#FileToEdit.txt"',i))
		
		
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "Meter" "Shape" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "X" "0" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "Y" "([MeterDisk%s_Name:Y]-[MeterDisk%s_Name:W]/2)" "#@#FileToEdit.txt"',i,i,i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "Shape" "Rectangle 0,0,#MaxWidth#,(\[MeterDisk%s_Name:H\]*1.75) | Fill Color 0,0,0,0 | StrokeWidth 0" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "MouseOverAction" "[!CommandMeasure DiskAnimation%s ""Stop 2""][!CommandMeasure DiskAnimation%s \"Execute 1\"]" "#@#FileToEdit.txt"',i,i,i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "MouseLeaveAction" "[!CommandMeasure DiskAnimation%s ""Stop 1""][!CommandMeasure DiskAnimation%s \"Execute 2\"]" "#@#FileToEdit.txt"',i,i,i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "LeftMouseUpAction" "\[%s:\\]" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "DynamicVariables" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "UpdateDivider" "-1" "#@#FileToEdit.txt"',i))
		
		
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "Meter" "Shape" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "X" "(#MaxWidth#/2-#Underliner_Width_%s#/2)" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "Y" "-5R" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "Shape" "Rectangle 0,0,#Underliner_Width_%s#,1 | Fill Color #AccentColor# | StrokeWidth 0" "#@#FileToEdit.txt"',i,i))
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "DynamicVariables" "1" "#@#FileToEdit.txt"',i))
		SKIN:Bang(string.format('!WriteKeyValue Underliner_%s "UpdateDivider" "-1" "#@#FileToEdit.txt"',i))
		
	end
	
end

User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 27th, 2018, 5:52 pm

Oh my god! Huuuge!!!
Please pack and upload the whole config. The involved skin also would be important as this code looks.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 27th, 2018, 6:10 pm

balala wrote:Oh my god! Huuuge!!!
Please pack and upload the whole config. The involved skin also would be important as this code looks.
First of all let me fill you in. The point is to make a skin that dynamically changes according to the disks (internal or external usb etc...) so if you unplug a usb, the meters will change for example.


and the "#@#FileToEdit.txt" is just an empty .txt that gets written when you mouseclick the red box. You can delete all of it's context whenerv you want, the lua script will write it again. That's how I've been working on it at least... do you face a problem? delete the whole .txt, refresh the skin, wait 2 seconds, click on it and boom, you have the code back ready to be worked on. Any change you make on the .txt would be irrelevant.
You do not have the required permissions to view the files attached to this post.