Zalerinian, on 07 August 2012 - 05:21 AM, said:
crazylady77, on 07 August 2012 - 04:20 AM, said:
I am trying to build a banking system that takes withdrawled money for a balance file located /disk/bal I keep getting a error
Heres the code
write ("Please enter the amount of money you would like to withdraw: ")
local money = tonumber(read())
for dont=1. money do
tFile = fs.open('/disk/bal', 'r')
current = tFile.read()
tFile.close()
hFile = fs.open('/disk/bal', 'w')
hFile.write(tonumber(current) - tonumber(read()))
hFile.close()
end
Error is
withdraw:5: attempt to call nil
Please someone help me fix this. Remember though it has to store and read the balance amount from a floppy disk.
try replacing
current = tFile.read()
with
current = tFile:read()
that should fix it.
No, that won't fix it, since he's using the FS API and not the IO API.
OP, does the file actually exist at /disk/bal? fs.open() will throw an error (which results in the first value returned being nil) if the file doesn't exist when you open it in read mode. Also, I don't think that that program will do what you think it will.