function Initialize()
file = io.open(SKIN:MakePathAbsolute('words.txt'), 'r')
end -- function Initialize
function Update()
wordsline = file:read("*line")
SKIN:Bang('!SetOption MeterStrMW Text '..'\" '..wordsline..' \"')
-- if wordline == nil then
-- file:close()
-- SKIN:Bang('!Refresh')
-- end
end -- function Update
i use the "if" to change the position, but something wrong in it~
So you want the script to output a new line from the text wile with each update cycle? Looks OK to me, but you have misspelled wordsline in the part you commented out. I think you might even simplify your code by just using
You probably don't want open a file and leave it open at all times. You would not be able to delete it or move it at all.
The following code will read all the lines of a file into a table, closing the file when it's done. Then on each update it will output the next line, looping around to the beginning again when it's done.
function Initialize()
local file = io.open(SKIN:MakePathAbsolute('words.txt'), 'r')
fLines = {}
for line in file:lines() do
table.insert(fLines, line)
end
file:close()
cLine = 1
end -- function Initialize
function Update()
SKIN:Bang('!SetOption', 'MeterStrMW', 'Text', fLines[cLine])
cLine = cLine % #fLines + 1
end -- function Update
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
MerlinTheRed wrote:So you want the script to output a new line from the text wile with each update cycle? Looks OK to me, but you have misspelled wordsline in the part you commented out. I think you might even simplify your code by just using
smurfier wrote:You probably don't want open a file and leave it open at all times. You would not be able to delete it or move it at all.
The following code will read all the lines of a file into a table, closing the file when it's done. Then on each update it will output the next line, looping around to the beginning again when it's done.
function Initialize()
local file = io.open(SKIN:MakePathAbsolute('words.txt'), 'r')
fLines = {}
for line in file:lines() do
table.insert(fLines, line)
end
file:close()
cLine = 1
end -- function Initialize
function Update()
SKIN:Bang('!SetOption', 'MeterStrMW', 'Text', fLines[cLine])
cLine = cLine % #fLines + 1
end -- function Update