It is currently April 19th, 2024, 9:01 am

Help with lua code

Get help with creating, editing & fixing problems with skins
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Help with lua code

Post by theimmersion »

I use this amazing notes skin.
I know its old but hope the author is still active and will update with some new (incorporate) features that i posted there. In mean time im trying to modify it myself the ugly way.

Summary, the notes are being added top wise and the whole skin is also moving upwards. Im using the skin towards the upper side of screen and the skin moving upwards is hitting the screen edge. I wanted it to go downwards and i accomplished it.
But also, i want the new notes to be the last entries rather than first and thats what i cant figure out.

This is the original part of the Lua code that adds and removes entries:

Code: Select all

function AddItem()
	local input, crlf = SKIN:GetVariable('Input'):gsub("\r\n", "#*CRLF*#")
	if input ~= "" then
		for i = 1, 15 do
			SKIN:Bang('!WriteKeyValue Variables Item'..(i+1)..' """'..SKIN:GetVariable('Item'..i):gsub("\n", "#*CRLF*#")..'""" "#CURRENTPATH#Notes.txt"')
		end
		SKIN:Bang('!WriteKeyValue Variables Item1 """'..input..'""" "#CURRENTPATH#Notes.txt"')
		SKIN:Bang('[!Move #CURRENTCONFIGX# (#CURRENTCONFIGY#-4-'..(SKIN:GetMeter('Input'):GetH()*(crlf+1))..')][!Refresh]')
	end
end

function DeleteItem(n)
	for i = n, 15 do
		SKIN:Bang('!WriteKeyValue Variables Item'..i..' """'..SKIN:GetVariable('Item'..(i+1)):gsub("\n", "#*CRLF*#")..'""" "#CURRENTPATH#Notes.txt"')
	end
	SKIN:Bang('!WriteKeyValue Variables Item16 "" "#CURRENTPATH#Notes.txt"')
	SKIN:Bang('[!Move #CURRENTCONFIGX# (#CURRENTCONFIGY#+4+'..SKIN:GetMeter('Item'..n):GetH()..')][!Refresh]')
end
This is what i modified to make the skin not move upwards:

Code: Select all

function AddItem()
	local input, crlf = SKIN:GetVariable('Input'):gsub("\r\n", "#*CRLF*#")
	if input ~= "" then
		for i = 1, 15 do
			SKIN:Bang('!WriteKeyValue Variables Item'..(i+1)..' """'..SKIN:GetVariable('Item'..i):gsub("\n", "#*CRLF*#")..'""" "#CURRENTPATH#Notes.txt"')
		end
		SKIN:Bang('!WriteKeyValue Variables Item1 """'..input..'""" "#CURRENTPATH#Notes.txt"')
		SKIN:Bang('[!Refresh]')
	end
end

function DeleteItem(n)
	for i = n, 15 do
		SKIN:Bang('!WriteKeyValue Variables Item'..i..' """'..SKIN:GetVariable('Item'..(i+1)):gsub("\n", "#*CRLF*#")..'""" "#CURRENTPATH#Notes.txt"')
	end
	SKIN:Bang('!WriteKeyValue Variables Item16 "" "#CURRENTPATH#Notes.txt"')
	SKIN:Bang('[!Refresh]')
end
I essentially replaced this:
SKIN:Bang('[!Move #CURRENTCONFIGX# (#CURRENTCONFIGY#-4-'..(SKIN:GetMeter('Input'):GetH()*(crlf+1))..')]
with this:
SKIN:Bang('[!Refresh]')

But i cant figure out how to make it append entries.
As i understood the code, it is rewriting all the values from itemN to itemN+1 which moves all the old notes down and the new note is being written on the item1. I tired to modify it to write to get the NextIndex stored in the skins variables section but nothing is happening.
This is what i tired.
Skin.ini:

Code: Select all

[Variables]
NextIndex=3
Lua script:

Code: Select all

function AddItem()
	local input, crlf = SKIN:GetVariable('Input'):gsub("\r\n", "#*CRLF*#")
	local index = SKIN:GetVariable('NextIndex')
		SKIN:Bang('!WriteKeyValue Variables Item'..index..' """'..input..'""" "#CURRENTPATH#Notes.txt"')
		SKIN:Bang('[!Refresh]')
	end
end
I assume i dont have to modify the DeleteItem function, just the AddItem function?

The logic is simple, i want the oldest notes (mostly used as ToDo:) to be the first entry and new ones at the bottom since im going throught the list top to bottom. Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with lua code

Post by balala »

I'd reorder the meters of the skin, reversing their order. The [Item16] and [Item16BG] should be on the first place, while [Item1] and [Item1BG] should be on the last:

Code: Select all

[Item16]
Meter=String
MeterStyle=sItem
Text=#Item16#

[Item16BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item16:W])
H=[Item16:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 16][!Update]

[Item15]
Meter=String
MeterStyle=sItem
Text=#Item15#

[Item15BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item15:W])
H=[Item15:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 15][!Update]

[Item14]
Meter=String
MeterStyle=sItem
Text=#Item14#

[Item14BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item14:W])
H=[Item14:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 14][!Update]

[Item13]
Meter=String
MeterStyle=sItem
Text=#Item13#

[Item13BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item13:W])
H=[Item13:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 13][!Update]

[Item12]
Meter=String
MeterStyle=sItem
Text=#Item12#

[Item12BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item12:W])
H=[Item12:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 12][!Update]

[Item11]
Meter=String
MeterStyle=sItem
Text=#Item11#

[Item11BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item11:W])
H=[Item11:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 11][!Update]

[Item10]
Meter=String
MeterStyle=sItem
Text=#Item10#

[Item10BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item10:W])
H=[Item10:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 10][!Update]

[Item9]
Meter=String
MeterStyle=sItem
Text=#Item9#

[Item9BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item9:W])
H=[Item9:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 9][!Update]

[Item8]
Meter=String
MeterStyle=sItem
Text=#Item8#

[Item8BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item8:W])
H=[Item8:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 8][!Update]

[Item7]
Meter=String
MeterStyle=sItem
Text=#Item7#

[Item7BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item7:W])
H=[Item7:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 7][!Update]

[Item6]
Meter=String
MeterStyle=sItem
Text=#Item6#

[Item6BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item6:W])
H=[Item6:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 6][!Update]

[Item5]
Meter=String
MeterStyle=sItem
Text=#Item5#

[Item5BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item5:W])
H=[Item5:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 5][!Update]

[Item4]
Meter=String
MeterStyle=sItem
Text=#Item4#

[Item4BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item4:W])
H=[Item4:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 4][!Update]

[Item3]
Meter=String
MeterStyle=sItem
Text=#Item3#

[Item3BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item3:W])
H=[Item3:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 3][!Update]

[Item2]
Meter=String
MeterStyle=sItem
Text=#Item2#

[Item2BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item2:W])
H=[Item2:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 2][!Update]

[Item1]
Meter=String
MeterStyle=sItem
Text=#Item1#

[Item1BG]
Meter=Image
MeterStyle=sItemBG
W=(73+[Item1:W])
H=[Item1:H]
MouseOverAction=[!ShowMeterGroup Edit][!SetVariable Item 1][!Update]
The .lua file shouldn't be touched.
Last edited by balala on November 28th, 2017, 2:26 pm, edited 1 time in total.
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Re: Help with lua code

Post by theimmersion »

Ok, ill do that. Thanks!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with lua code

Post by balala »

theimmersion wrote:Ok, ill do that. Thanks!
Let me know if you've succeeded, when finished.
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Re: Help with lua code

Post by theimmersion »

Ok, that kinda works. But thats honestly even a dirtier workaround than figuring out the lua script. xD
The distance from the label where you click to add a note gets far down. Adding a y=-20 fixes it a bit but more notes that are being added are making each note go further from each other away. Very inconsistent. Ill try fix it. Also the rearange buttons have than to be flipped as well.
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Re: Help with lua code

Post by theimmersion »

I figured it out how how to add based on index.

Code: Select all

function AddItem()
	local index = SKIN:GetVariable('NextIndex')
	local input, crlf = SKIN:GetVariable('Input'):gsub("\r\n", "#*CRLF*#")
	SKIN:Bang('!WriteKeyValue Variables Item'..index..' """'..input..'""" "#CURRENTPATH#Notes.txt"')
	SKIN:Bang('[!Refresh]')
end
I had a rogue end when i tried and thats what messed things up. Now it works almost perfectly.
Almost because theres one thing i want to figure out as a safeguard for the index tracking in case the user manually would delete the notes within the file itself. So, it would be nice if i could somehow itterate through the note file and its variables and stop the index between 1 and 15 that has empty value. That way, i would not need to use #NextIndex#+1 and #NextIndex#-1. As it now stands, if user would to delete any of the values in the note.txt the index would be s**ewed. xD
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with lua code

Post by balala »

theimmersion wrote:Almost because theres one thing i want to figure out as a safeguard for the index tracking in case the user manually would delete the notes within the file itself. So, it would be nice if i could somehow itterate through the note file and its variables and stop the index between 1 and 15 that has empty value. That way, i would not need to use #NextIndex#+1 and #NextIndex#-1. As it now stands, if user would to delete any of the values in the note.txt the index would be s**ewed. xD
Not sure this is a simple workaround. Probably neither impossible isn't, but definitely not simple.
In the meantime I figured out another solution of your last issue, described above. I didn't touch the lua code neither now. But if you fixed the code and it works now as you wanted, I leave my solution aside for now.
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Re: Help with lua code

Post by theimmersion »

Oh do post. Maybe its better than mine or maybe one day ill need that solution instead of the one im currently using. Ya never know. Maybe ill encounter a similar skin with a really complicated lua. Also, some other people might find that useful as well. In any case, thanks for the help as usual Balala. :rosegift: (take this rose, consider it as a bro love... because theres no other gift emoji here) :rofl:
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with lua code

Post by balala »

theimmersion wrote:Oh do post. Maybe its better than mine or maybe one day ill need that solution instead of the one im currently using. Ya never know. Maybe ill encounter a similar skin with a really complicated lua. Also, some other people might find that useful as well. In any case, thanks for the help as usual Balala. :rosegift: (take this rose, consider it as a bro love... because theres no other gift emoji here) :rofl:
Thanks for the gift...
I'll post my solution tomorrow, because here is almost midnight (EET) and I'm going now to sleep. Tomorrow in the morning I have to go to work (shit...). Sorry for the inconvenience.
User avatar
theimmersion
Posts: 55
Joined: November 27th, 2016, 1:51 pm

Re: Help with lua code

Post by theimmersion »

No problem. I aint running away. :)

In mean time, i posted my edited skin to the original thread found here if anyone wants to examine it or use it.