11 posts
Posted 20 March 2014 - 04:45 PM
I'm trying to figure out a way how to create a list of computer ID's for my Computer Network. Right now, I have figured out how to tell another computer, the other computers Id and a unique password, now I would like to somehow save that Computer Id into a list, and be able to read it line by line. I searched the internet for an hour, but didn't find an easy enough answer.
Thanks in advance :)/>
8543 posts
Posted 20 March 2014 - 05:27 PM
Moved to Ask a Pro.
7083 posts
Location
Tasmania (AU)
Posted 20 March 2014 - 07:27 PM
Save it into a temporary list that lasts the duration of the program, or a permanent copy to the computer's drive…?
120 posts
Posted 20 March 2014 - 11:17 PM
I agree with Bomb Bloke.
fs.makeDir(TempProgramFiles)
shell.setDir(TempProgramFiles)
fs.open("tempfile.tmp","w")
fs.writeLine("-LISTSTART-")
fs.writeLine("Listitem")
fs.writeLine("-LISTEND-")
fs.close()
is all you need to write.
Then, at the end, do:
shell.setDir(..)
shell.setDir(TempProgramFiles)
fs.delete("tempfile.tmp")
7083 posts
Location
Tasmania (AU)
Posted 21 March 2014 - 08:22 AM
To be clear, those weren't suggestions in my post - I don't "get" which of those two separate tasks FireDust is asking about.
2151 posts
Location
Auckland, New Zealand
Posted 21 March 2014 - 09:34 AM
All you need to do is put them in to a table, use something like this:
--create the table (list)
local computerIDs = {}
--each time you receive an id, do this
table.insert(computerIDs, id)
--loop over all ids (if you want to do it)
for i, id in ipairs(computerIDs) do
print('ID: '..tostring(id))
end
If you want to save/load the table you'll need to serialise it:
--load, note, you will need to save the file at least once first
local h = fs.open('ids', 'r')
if h then
local computerIDs = textutils.unserialize(h.readAll())
h.close
end
--saving
local h = fs.open('ids', 'w')
if h then
h.write(textutils.serialize(computerIDs)
h.close()
end
For more info about tables check out
this tutorial.
Edited on 21 March 2014 - 08:35 AM