Reputation: 11
I am writing a script to add one line in a .txt per video while using MPV.
However, I am getting a weird error on line 68 with the for loop.
It merely tells me: no error. If I add an error parameter to file:write(message, error), it gives me another error message, stating: bad argument #2 to 'write' (string expected, got function)
. Any help would be appreciated.
function on_file_end(event)
if not paused then totaltime = totaltime + os.clock() - lasttime end
local message = (totaltime .. "s, " .. timeloaded .. ", " .. filename)
local lines = {}
local file = io.open(logpath, "r+")
if file_exists(logpath) then
for l in file:lines() do
if not l:find(message, 1, true) then
lines[#lines+1] = 1
file:write(message)
end
end
file:close()
end
end
Upvotes: 1
Views: 137
Reputation: 28974
bad argument #2 to 'write' (string expected, got function)
error
is not an "error parameter" it is a global function that allows to raise your own errors in Lua.
See https://www.lua.org/manual/5.4/manual.html#pdf-error
Upvotes: 1