This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
dcleondc's profile picture

how to wright and read list

Started by dcleondc, 02 September 2012 - 02:21 AM
dcleondc #1
Posted 02 September 2012 - 04:21 AM
hello, here is what i got

if not fs.exists("/request.txt") then
    local file = io.open("/request.txt", "w")
    file:write("{ }")
    file:close()
end
if not fs.exists("/.submitted.txt") then
    local file = io.open("/.submitted.txt", "w")
    file:write("{ }")
    file:close()
end
local function getList()
local file = io.open("/request.txt", "r")
sNames = file:read()
file:close()
print(sNames)
requestList = textutils.unserialize(sNames)
print(requestList)
end
local function getSubmitted()
local file = io.open("/.submitted.txt", "r")
sSubmitted = file:read()
file:close()
tSubmitted = textutils.unserialize(sSubmitted)
end

local function addPlayer( sName )
getList()
getSubmitted()
table.insert(requestList, sName)
sNames = textutils.serialize(requestList)
local file = io.open("/request.txt", "w")
file:write(sNames)
file:close()
table.insert(tSubmitted, sName )
sSubmitted = textutils.serialize(tSubmitted)
local file = io.open("/.submitted.txt", "w")
file:write(sSubmitted)
file:close()
print ("Request Sent.")
sleep(1)
end
shell.run("clear")
print("Type Name")
sName = io.read()
addPlayer(sName)
shell.run("clear")
getList()
the code is from a program that i had someone make for me a while ago.
but when i do print(sNames) it comes out in this format

{[1]="25",[2]="10",[3]="26",}

and i want to know how to print it in this format

25,10,26
Lettuce #2
Posted 02 September 2012 - 04:51 AM
I'm unsure what the program is supposed to do, and what part is for what, but it looks like it's reading/writing from a plain text file.
I once printed a table's contents with
print([1])
print([2])
etc.
So why don't you see if that works? If it doesn't, please elaborate on what it's for so I know what I'm looking at. (and so will anyone else if I can't help you.)
dcleondc #3
Posted 02 September 2012 - 05:10 AM
i did

for i=1,num do
    write(requestList[i]..",")
end
and it worked
Lettuce #4
Posted 02 September 2012 - 06:07 AM
O…kay. Well, if I helped I'm glad, if not, still glad you got it working. Good luck with whatever it is that does.