It is currently March 28th, 2024, 10:41 am

[Solved]Variable not working in a script.

Get help with creating, editing & fixing problems with skins
Post Reply
misstake
Posts: 5
Joined: August 19th, 2021, 3:57 pm

[Solved]Variable not working in a script.

Post by misstake »

Hi,
I'd need some help again for my skin.

I'm currently using this script to read my iCue log File.

Code: Select all

[Variables]
FiletoRead=E:\Documents\Skins\SideBAR4\@Resources\iCue logs\corsair_cue_20210825_12_53_37.csv
LinesToTail=1
SecondsBetweenRead=5
ChildPrefix=MeasureLine

Code: Select all

function Initialize()
  
	fileToRead = SKIN:GetVariable('FileToRead')
	linesToTail = tonumber(SKIN:GetVariable('LinesToTail'))
	childPrefix = SKIN:GetVariable('ChildPrefix')

end

function Update()
	local inputFile = io.open(fileToRead, 'r')
	local text, ch
	local pos = -1
	local i = 1

	repeat
		inputFile:seek("end", pos - 1)
		ch = inputFile:read(1)
		if ch == '\n' then
			text = inputFile:read(-pos)
			if text ~= nil then
				SKIN:Bang('!SetOption', childPrefix..i, 'String', string.match(text, "^(.-)\n"))
				SKIN:Bang('!UpdateMeasure', childPrefix..i)
				i = i + 1
				pos = pos - 1
			end
		end
		pos = pos - 1
	until (i > linesToTail)

	io.close(inputFile)

	SKIN:Bang('!UpdateMeter', '*')
	SKIN:Bang('!Redraw')

	return 0
end
It works fine except that I have to manually enter the File path in my variables everytime there is a new one.
Now I'm trying to make it automatically get the right file to read.

I use the Fileview plugin to get the latest file then put it in my Variables like below

Code: Select all

[Variables]
FileName=[mIndex1Name]
FiletoRead=E:\Documents\Skins\SideBAR4\@Resources\iCue logs\#FileName#
LinesToTail=1
SecondsBetweenRead=5
ChildPrefix=MeasureLine
I also tried

Code: Select all

FiletoRead=E:\Documents\Skins\SideBAR4\@Resources\iCue logs\[mIndex1Name]
I tested "FiletoRead" and it return the right path with the latest Csv file in both case
Currently: E:\Documents\Skins\SideBAR4\@Resources\iCue logs\corsair_cue_20210825_12_53_37.csv


I suspect that the script is not able to get the output of [mIndex1Name] or #FileName# and would need to have it directly defined in it s own file, maybe like this :

Code: Select all

function Initialize()
	fileName = SKIN:GetVariable('FileName')
	filePath = SKIN:GetVariable('FilePath')
And then fileToRead = Filepath+Filename
I just don't know how to do it correctly. Or even if I'm right somehow.
Last edited by misstake on August 25th, 2021, 10:54 pm, edited 1 time in total.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm
Contact:

Re: Variable not working in a script.

Post by death.crafter »

misstake wrote: August 25th, 2021, 6:10 pm

Code: Select all

[Folder]
Measure=Plugin
Plugin=FileView
Path=<path>
ShowDotDot=0
ShowFolder=0
SortType=Date
SortDateType=Modified
Count=1

[File]
Measure=Plugin
Plugin=FileView
Path=[Folder]
Index=1
Type=FilePath

Code: Select all

function Initialize()
	linesToTail = tonumber(SKIN:GetVariable('LinesToTail'))
	childPrefix = SKIN:GetVariable('ChildPrefix')
end

function Update()
	fileToRead = SKIN:GetMeasure('File'):GetStringValue()
	if fileToRead==nil then
		SKIN:Bang('!Log', 'File not found!', 'ERROR')
		SKIN:Bang('!PauseMeasure', SELF:GetName())
		return
	end
	...
	<rest of the code>
	...
end
misstake
Posts: 5
Joined: August 19th, 2021, 3:57 pm

Re: Variable not working in a script.

Post by misstake »

Perfectly works, thank you
Post Reply