Yes you can by saving it as a table, but what you seem to be doing is very bulky?
try this (not tested):
-- Initialise table
a = {}
-- Initialise monitor
mon = peripheral.wrap("monitor_side")
mon.setTextScale(0.5)
mon.setTextColour(colours.black)
mon.setBackgroundColour(colours.white)
-- lazy way to clear terminal screen
function cs()
term.clear()
term.setCursorPos(1,1)
end
-- constant loop, to update monitor when someone adds a new message, for multi user this is also very easy
while true do
i = 1
for _, v in ipairs do
mon.setCursorPos(1,1)
mon.write(v)
i = i + 1
end
print("> Message: ")
local msg = read()
print("> Your username: ")
local user = read()
newString = msg.." ~ "..user
table.insert(a, newString)
end
-- Code not tested! Should work though! Not got minecraft on me!
try that!
To store it, just use a config api Here is the saveConfig and loadConfig snippets from my api, just use them to save the table and then read it after:
function saveConfig(table, file)
fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
fConfig.write(textutils.serialize(table))
fConfig.close()
end
function loadConfig(file)
fConfig = fs.open(file, "r")
ret = textutils.unserialize(fConfig.readAll())
return ret
end
Then instead when you iterate the table it will automatically go to the bottom of the screen if you don't delete comments, so if I was you I would add a way of removing them, although this can be done like this:
x, y = mon.getSize()
if y < #tMessages then
repeat
table.remove(tMessages, 1)
until #tMessages <= y
end
-- do the for loop here
Put it all together and make sure it works, the part that checks it doesn't write more messages than the monitors size needs to go before the for loop!
Hope this helps, if not email me:
[email protected] or pm me on here, and I shall make one for you
Edited by DannySMc, 31 October 2014 - 05:32 PM.