Posted 18 November 2013 - 07:59 PM
im trying to read a file, print to screen and do this every few minutes.
also when the result has more lines than the screen has, the results slowly scroll p.
im thinking I should be using arrays but have no idea where to start to be honest.
so far I have -
any help would be appreciated
also when the result has more lines than the screen has, the results slowly scroll p.
im thinking I should be using arrays but have no idea where to start to be honest.
so far I have -
local cPrint = function(text)
local x2,y2 = term.getCursorPos()
local x,y = term.getSize()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
local mon = peripheral.wrap("left") -- get the monitor
mon.setTextScale(1.2) -- set the text scale
term.redirect(mon) -- redirect output to the monitor
repeat
local time = os.time()
time = textutils.formatTime(time, true)
local f = io.open("disk/listings.yml", "r")
if fs.exists("disk/listings.yml") == false then
print("File not found!")
return
end
--term.clear()
cPrint ("Auction Listings \n")
local lines = {}while true do
local line = f:read()
if line == nil then
print("\n updated: "..time)
break
end
local result = string.gsub(line, " ", "") -- remove line breaks
if (string.match(result,"type")) ~= nil then
type = result
end
if (string.match(result,"amount")) ~= nil then
amount = result
end
if (string.match(result,"seller")) ~= nil then
seller = result
end
if (string.match(result,"price")) ~= nil then
price = result
end
if (string.match(result,"time")) ~= nil then
cPrint("Item "..type.." -- "..amount.." -- "..seller.." -- Sell "..price)
cPrint("----------------------------------------------------------------------------------")
end
lines[#lines+1] = line
end
until os.pullEvent() ~= 'key'
term.restore()
any help would be appreciated