Posted 02 July 2014 - 04:15 PM
Hello,
Continuing the same problem from the last post, it gives me error when I am calling the function newID.
I am not sure what change I made after last time running the function, and for me it does not seem wrong.
the error is attempt to call number on line 96, which is in the function of mainMenu, newID().
http://pastebin.com/buswPGHh, if you think it is easier to see it on the pastebin.
Thanks in advance,
Continuing the same problem from the last post, it gives me error when I am calling the function newID.
I am not sure what change I made after last time running the function, and for me it does not seem wrong.
the error is attempt to call number on line 96, which is in the function of mainMenu, newID().
http://pastebin.com/buswPGHh, if you think it is easier to see it on the pastebin.
Thanks in advance,
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")
if disk_f == nil then
term.setCursorPos(1,4)
print("File or code does not exist.")
sleep(3)
else
local disk_pw = disk_f:read("*l")
disk_f:close()
local lastID_f = io.open("lastid.txt", "r")
local lastID = lastID_f:read("*l")
lastID_f:close()
while true do
term.setCursorPos(1,4)
print("Checking..")
sleep(0.3)
for fileNumber = 1, lastID do
print("Checking : "..fileNumber..".txt")
local check_f = io.open(fileNumber..".txt","r")
local line = check_f:read("*l")
sleep(0.1)
if line == disk_pw then
local nick = check_f:read("*l")
print("Username: " ..nick)
print("Press any key to exit")
os.pullEvent()
return
end
end
print("Invalid, press any key to exit.")
os.pullEvent()
return
end
end
function newID()
local genCode = RandomString()
if disk.isPresent(diskDriveSide) == false then
term.setCursorPos(1,4)
print("Insert Disk!")
sleep(3)
else
term.setCursorPos(1,4)
term.write("Please type in the player name : ")
local playerName = read()
disk.setLabel(diskDriveSide, "SPCard - " ..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()
term.setCursorPos(1,6)
print("Generated!")
sleep(2)
end
end
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
if disk.isPresent(diskDriveSide) == false then
term.setCursorPos(1,4)
print("Insert Disk!")
sleep(3)
else
compare()
end
elseif key == "2" then
newID()
else
sleep(0.1)
end
end
while true do
mainMenu()
end
Edited on 02 July 2014 - 02:35 PM