Rainmeter gives "Script: File not valid" for the following LUA Script and I can't find an error.
The script should read a text file line by line in which data records are created line by line, similar to a CSV file, except that the separator is a "~" (see at the end).
When a skin element is clicked, the variable cng_Value is set with the new value and cng_Field with the field to be changed like "z2_s5" (z=Zeile/Row,s=Spalte/Column --> Row 2 - Column 5). The script should replace cng_Value in the row/column with the value of cng_Field (row/column). Afterwards, all data records in the array are written back to the file, including the changed data.
The skin should issue daily reminders for certain events.
Could someone find the error please?
alt_line.lua:
Code: Select all
local cng_Value = SKIN:GetVariable('cng_Value')
local z_s_cng= SKIN:GetVariable('cng_Field')
local z_cng = tonumber(string.match(z_s_cng, "z(.-)_"))
local s_cng = tonumber(string.match(z_s_cng, "s(.*)$"))
-- File path
local file = "dayly_todo.txt"
local base_dir = SKIN:GetVariable('path')
local file_path = base_dir .. file
-- Open file in read-write mode
local read_file = io.open(file_path, "w")
-- reads file in an array
local zeilen = {}
if read_file then
for line in read_file:lines() do -- Read file line by line and store the lines in an array
local einzelwerte = {}
for wert in line:gmatch("[^~]+") do
table.insert(einzelwerte, wert) -- Insert the individual values into the inner array
end
table.insert(zeilen, einzelwerte) -- Insert the array of single values into the main array
end
end
--Initialize data variable
local data = ""
-- write the lines including changed data into the variable data
for z, einzelwerte in ipairs(zeilen) do
for s, wert in ipairs(einzelwerte) do
if s == s_cng and z == z_cng then
data = data .. "~" .. cng_Value -- writes the changed value it in the line
else
data = data .. "~" .. wert --writes the previous value into the line
end
end
data = string.sub(data, 1, -2) -- Removes the last character ~
data = data .. "\n" -- adds a line break at the end of the line
end
if write_file then
write_file:write(data) -- Write the variable data into the file
end
write_file:close() -- Close file
SKIN:Bang('!Refresh')
Code: Select all
ASS 100~1~1~1~1~1~1~1~6:30
Rosuvastatin~1~1~1~1~1~1~1~6:30
Pantoprazol (1h v Essen)~1~1~1~1~1~1~1~17:00
Vit. D+K~0~0~0~0~0~0~1~10:00