The Skin/Script helps me control an USB-relay unit with 8 channels. (see the attached image)
To make Lua read a file is quiet easy, but to make Lua write is more difficult.
My progress:
1. the Script didn't write to file at all.
2. the Script worked for the first time, but did only write the first line.
3. the Script worked better, but it did write the whole file in one line.
4. found out about the "\n" switch and how important single quotes can be.
And now it works like a charm.
I appreciate every comment.
Code: Select all
function Initialize()
end
function Reset()
local FilePath = SKIN:MakePathAbsolute('ISTXb.inc')
local File = io.open(FilePath, 'r')
if not File then
print('Text1: unable to open file for read at ' .. FilePath)
return
end
local Contents = {}
for Line in File:lines() do
table.insert(Contents, Line)
end
File:close()
local FilePath = SKIN:MakePathAbsolute('ISTX.inc')
local File = io.open(FilePath, 'w')
if not File then
print('Text1: unable to open file for write at ' .. FilePath)
return
end
local iCount = #Contents
for i = 1, iCount do
File:write(Contents[i], '\n')
end
File:close()
[color=#40FF80]--SKIN:Bang('!Refresh', 'Vista Rainbar\Power Chose', 'PowCho.ini')[/color]
end