Posted 11 November 2014 - 12:22 AM
I am trying to make a very nice os program for my computers and I am having a hell of a time trying to use tables to hold multiple peices of information.
I serialize the data into a new file and cannot get them to return.
I use this to serialize for a test.
then I use this to unserialize test.
I serialize the data into a new file and cannot get them to return.
I use this to serialize for a test.
function save(table,name)
local file = fs.open(name,"w")
file.write(textutils.serialize(table))
file.close()
end
local myTable = {}
term.clear()
term.setCursorPos(1,1)
print("What is your name?")
write("?: ")
input = read()
myTable["username"] = input
term.clear()
term.setCursorPos(1,1)
print("What is you password?")
write("?: ")
input = read("*")
myTable["pwd"] = input
term.clear()
term.setCursorPos(1,1)
print("Type a color.")
write("?: ")
input = read()
myTable["color"] = input
term.clear()
term.setCursorPos(1,1)
save(myTable,"info")
print("Table Made")
then I use this to unserialize test.
function load(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
textutils.unserialize(data)
file.close()
end
function resetLine(x,y)
term.setCursorPos(x,y)
term.clearLine()
term.setCursorPos(x,y)
end
function loadLogo()
local image = paintutils.loadImage("logo")
paintutils.drawImage(image, 3, 1)
end
function LoadingBar()
if pocket then
middle = 13 - 3
term.setCursorPos(10,19)
for i = 1, 4, 1 do
print("-oooO-")
sleep(0.5)
resetLine(10,19)
print("-ooOo-")
sleep(0.5)
resetLine(10,19)
print("-oOoo-")
sleep(0.5)
resetLine(10,19)
print("-Oooo-")
sleep(0.5)
resetLine(10,19)
print("-oOoo-")
sleep(0.5)
resetLine(10,19)
print("-ooOo-")
sleep(0.5)
resetLine(10,19)
end
else
middle = 26 - 5
for i = 1, 3 , 1 do
term.setCursorPos(21,18)
print("-ooooooooO-")
sleep(1)
resetLine(21,18)
print("-oooooooOo-")
sleep(1)
resetLine(21,18)
print("-ooooooOoo-")
sleep(1)
resetLine(21,18)
print("-oooooOooo-")
sleep(1)
resetLine(21,18)
print("-ooooOoooo-")
sleep(1)
resetLine(21,18)
print("-oooOooooo-")
sleep(1)
resetLine(21,18)
print("-ooOoooooo-")
sleep(1)
resetLine(21,18)
print("-oOooooooo-")
sleep(1)
resetLine(21,18)
print("-Ooooooooo-")
sleep(1)
resetLine(21,18)
end
end
term.setCursorPos(1,1)
end
term.clear()
term.setCursorPos(1,1)
load("info")
print(myTable[username])
print(myTable[pwd])
print(myTable[color])