return numbers from a log (.txt)
Posted: Sun Mar 02, 2014 8:15 am
I have been trying to read a log file in order to get the numbers from it. The list in the log file looks something like this:
Tried using this function:
but it returns
I am trying to do something like
Basically trying to get the number's in the list into the variable number. Keeps coming up with nil value.
Code: Select all
Slot
71
72
74
75
76
77Code: Select all
function checkSlots()
local lines = {}
local filename = getExecutionPath() .. "/logs/"..player.Name..".txt"
local file, err = io.open(filename, "r");
if( not file ) then
print("File not found");
else
-- read the lines in table 'lines'
for line in io.lines(filename) do
table.insert(lines, line)
end
table.concat(lines, "\n")
for k,v in pairs(lines) do
local number = file:read(k, "*n")
print(number);
end
file:close()
end
endCode: Select all
Command> checkSlots()
Sl
ot
72
75
77
nilCode: Select all
for k,v in pairs(lines) do
local number = file:read(k, "*n")
if type(number) == "number" then
item = inventory.BagSlot[number]
if not (item.Id == 208679 or item.Id == 208682 or item.Id == 0) and item.Quality < 3 then
print(item.Name)
end
end
end