It calls nil when it is writing some info to a file. Please look at the code linked below.
CODE
acFile = fs.open("accounts/"..name,"r")
rednet.open("back")
while true do
id,request = rednet.receive()
if request == "balance" then
id,name = rednet.receive(.5)
id,pass = rednet.receive(.5)
--#if pass ~= nil or name ~= nil then
if pass ~= nil and name ~= nil then
--#check if exist
if not fs.exists('Accounts/'..name) then return; end
local account = fs.open("Accounts/"..name,"r")
local accountInfo = {}
for line in account.readLine do
accountInfo[#accountInfo+1] = line
end
account.close()
if accountInfo[1] == pass then
rednet.send(id,accountInfo[2])
end
end
elseif request == "transfer" then
--#got rid of id cause its not being used
_,name = rednet.receive(.5)
_,pass = rednet.receive(.5)
_,to = rednet.receive(.5)
_,ammount = rednet.receive(.5)
--#if name ~= nil or pass ~= nil or to ~= nil or ammount ~= nil then
if name ~= nil and pass ~= nil and to ~= nil and ammount ~= nil then
--#check if exist
if not fs.exists('Accounts/'..name) then return; end
if not fs.exists('Accounts/'..to) then return; end
local account = fs.open("Accounts/"..name,"r")
local accountInfo = {}
for line in account.readLine do
print(line)
--#accountInfo[#accountInfo+1] = line --this one is just preference
table.insert(accountInfo,line)
end
account.close()
if pass == accountInfo[1] then
if fs.exists("Accounts/"..to) == true then
local tmpPerson = fs.open("Accounts/"..to,"r")
local personInfo = {}
for line in tmpPerson.readLine do
--#personInfo[#personInfo+1] = line --this one is just preference
table.insert(personInfo,line)
end
tmpPerson.close()
if tonumber(accountInfo[2]) >= ammount then
personInfo[2] = tonumber(personInfo[2])+ammount
print('added '..personInfo[2])
local person = fs.open("Accounts/"..to,"w")
--#for i=0, #personInfo do --mainly causing the java error i believe
for i=1, #personInfo do
person.writeLine(personInfo[i])
end
person.close()
local account = fs.open("Accounts/"..name,"w")
accountInfo[2] = tonumber(accountInfo[2])-ammount
--#for i=0, #accountInfo do --mainly causing the java error i believe
for i=1, #accountInfo do
--#person.writeLine(accountInfo[i])
account.writeLine(accountInfo[i])
end
account.close()
--#person.close() moved higher up
end
end
end
end
end
end
If you look closely I do.Why do you open the name file for writing, but never write anything to it?
Thank you! You are a literal genius!Hi LeviM, you've gotten pretty far on that bank program!
Your code thats throwing a java exception has a number of OBO errors.
below are the fixes that make it run correctly.Spoiler
rednet.open("back") while true do id,request = rednet.receive() if request == "balance" then id,name = rednet.receive(.5) id,pass = rednet.receive(.5) --#if pass ~= nil or name ~= nil then if pass ~= nil and name ~= nil then --#check if exist if not fs.exists('Accounts/'..name) then return; end local account = fs.open("Accounts/"..name,"r") local accountInfo = {} for line in account.readLine do accountInfo[#accountInfo+1] = line end account.close() if accountInfo[1] == pass then rednet.send(id,accountInfo[2]) end end elseif request == "transfer" then --#got rid of id cause its not being used _,name = rednet.receive(.5) _,pass = rednet.receive(.5) _,to = rednet.receive(.5) _,ammount = rednet.receive(.5) --#if name ~= nil or pass ~= nil or to ~= nil or ammount ~= nil then if name ~= nil and pass ~= nil and to ~= nil and ammount ~= nil then --#check if exist if not fs.exists('Accounts/'..name) then return; end if not fs.exists('Accounts/'..to) then return; end local account = fs.open("Accounts/"..name,"r") local accountInfo = {} for line in account.readLine do print(line) --#accountInfo[#accountInfo+1] = line --this one is just preference table.insert(accountInfo,line) end account.close() if pass == accountInfo[1] then if fs.exists("Accounts/"..to) == true then local tmpPerson = fs.open("Accounts/"..to,"r") local personInfo = {} for line in tmpPerson.readLine do --#personInfo[#personInfo+1] = line --this one is just preference table.insert(personInfo,line) end tmpPerson.close() if tonumber(accountInfo[2]) >= ammount then personInfo[2] = tonumber(personInfo[2])+ammount print('added '..personInfo[2]) local person = fs.open("Accounts/"..to,"w") --#for i=0, #personInfo do --mainly causing the java error i believe for i=1, #personInfo do person.writeLine(personInfo[i]) end person.close() local account = fs.open("Accounts/"..name,"w") accountInfo[2] = tonumber(accountInfo[2])-ammount --#for i=0, #accountInfo do --mainly causing the java error i believe for i=1, #accountInfo do --#person.writeLine(accountInfo[i]) account.writeLine(accountInfo[i]) end account.close() --#person.close() moved higher up end end end end end end
If you look closely I do.Why do you open the name file for writing, but never write anything to it?