Posted 01 July 2014 - 02:16 PM
So, I was making a program that included editing .txt file.
It was doing well on opening the file, editing, and saving and etc.
However when it gives me the error on the line 15 of "attempt to call nil"
I have tried all of the things but does not work.
What is wrong with it? I just did the same thing that I did to other parts of the code that included opening the file.
It was doing well on opening the file, editing, and saving and etc.
However when it gives me the error on the line 15 of "attempt to call nil"
I have tried all of the things but does not work.
What is wrong with it? I just did the same thing that I did to other parts of the code that included opening the file.
local diskDriveSide = "left"
function RandomString()
length = 16
if length < 1 then return nil end
local array = {}
for i=1, length do
array[i] = string.char(math.random(32,126))
end
return table.concat(array)
end
function compare()
local disk_f = io.open("disk/pw.txt", "r")
local disk_pw = disk_f:write("*l")
disk_fi:close()
local lastID_f = io.open("lastid.txt", "r")
local lastID = lastID_f:read("*l")
lastID_f:close()
while false do
for fileNumber = 1, lastID do
local check_f = io.open(fileNumber.. ".txt","r")
local line = check_f:read("*l")
if line == disk_pw then
local nick = check_f:read("*l")
print(nick)
return true
else
return false
end
end
end
end
function newID()
local genCode = RandomString()
if disk.isPresent(diskDriveSide) == false then
print("Insert Disk!")
sleep(3)
else
term.setCursorPos(1,4)
term.write("Please type in the player name : ")
local playerName = read()
disk.setLabel(diskDriveSide, "IDCard - " ..playerName)
local disk_pw = io.open("disk/pw.txt", "w")
disk_pw:write(genCode)
disk_pw:close()
local root_lastID = io.open("lastid.txt","r")
local lastID = root_lastID:read("*l")
root_lastID:close()
root_lastID = io.open("lastid.txt","w")
newID = lastID+1
root_lastID:write(newID)
root_lastID:close()
local root_newID = io.open(newID..".txt","w")
root_newID:write(genCode)
root_newID:write("\n")
root_newID:write(playerName)
root_newID:close()
end
term.setCursorPos(1,6)
print("Generated!")
sleep(2)
end
function mainMenu()
term.clear()
term.setCursorPos(1,1)
print("1. Verify")
print("2. Make New ID Card")
local event, key = os.pullEvent("char")
if key == "1" then
compare()
elseif key == "2" then
newID()
else
sleep(0.1)
end
end
while true do
mainMenu()
end