This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lewisk3's profile picture

Help Error: Bankserver:75: Attemp To Perform Arthmetic __add On Nil And Number

Started by Lewisk3, 31 October 2013 - 04:38 PM
Lewisk3 #1
Posted 31 October 2013 - 05:38 PM
Heres My Code
Client
Spoiler

--keywords--
-- withdraw
-- deposit
--balance
--transfer-from
--transfer-to
--login
--creA
--delA
rednet.open("top")
-- ESAY USE --
function cp(x,y)
term.setCursorPos(x,y)
end
function bcolor(color)
term.setBackgroundColor(color)
end
function tcolor(color)
term.setTextColor(color)
end
--- END OF ESAY USE --
-- Config --
if fs.exists("config") then
file = fs.open("config","r")
text = file.readLine()
id = file.readLine()
file.close()
else
file = fs.open("config","w")
file.writeLine("Enter Server ID Below.")
file.writeLine("0")
file.close()
file = fs.open("config","r")
text = file.readLine()
id = file.readLine()
file.close()
end
-- /config --
function ain()
term.setBackgroundColor(colors.black)
  term.clear()
  term.setCursorPos(10,1)
  term.setBackgroundColor(colors.blue)
  print " Kcraft Bank		  "
  term.setCursorPos(31,1)
  term.setBackgroundColor(colors.red)
  print "X"
  term.setBackgroundColor(colors.lightBlue)
  term.setCursorPos(10,2)
  print "					  "
  term.setCursorPos(10,3)
  print "	 Username:	    "
  term.setCursorPos(10,4)
  print "					  "
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(11,4)
  print "				   "
  term.setCursorPos(10,5)
  term.setBackgroundColor(colors.lightBlue)
  print "	 Password:	    "
  term.setCursorPos(10,6)
  print "					  "
  bcolor(colors.lightGray)
  cp(11,6)
  print "				   "
  bcolor(colors.lightBlue)
  term.setCursorPos(10,7)
  print "					  "
  term.setBackgroundColor(colors.lightGray)
   cp(11,4)
   
    user = read()
   
    cp(11,6)
   
    pass = read()
end
function putin()
term.setCursorPos(1,6)
term.setBackgroundColor(colors.gray)
print "											 "
term.setCursorPos(1,7)
print " "
term.setCursorPos(2,7)
term.setBackgroundColor(colors.lightGray)
print "										   "
term.setCursorPos(45,7)
term.setBackgroundColor(colors.gray)
print " "
term.setCursorPos(1,8)
print "											 "
term.setCursorPos(2,7)
term.setBackgroundColor(colors.lightGray)
input = read()
end
function bank()
main = false
bcolor(colors.lightBlue)
term.clear()
i = paintutils.loadImage("blogo")
paintutils.drawImage(i,1,1)
cp(1,6)
print "----------------------------------------------------"
-- print choices --
bcolor(colors.lightBlue)
term.setCursorPos(1,11)
print "Withdraw"
cp(9,11)
bcolor(colors.green)
print "X"
bcolor(colors.lightBlue)
cp(1,12)
print "Deposit "
cp(9,12)
bcolor(colors.green)
print "X"
bcolor(colors.lightBlue)
cp(1,13)
print "Balance "
cp(9,13)
bcolor(colors.green)
print "X"
bcolor(colors.lightBlue)
cp(1,14)
print "Transfer"
cp(9,14)
bcolor(colors.green)
print "X"
bcolor(colors.lightBlue)
cp(1,15)
print "Logout  "
cp(9,15)
bcolor(colors.green)
print "X"
bcolor(colors.lightBlue)
ibank = true
while ibank do
local event, button, X, Y = os.pullEvent("mouse_click")
  if X == 9 and Y == 11 and button == 1 then
  cp(1,7)
   term.setBackgroundColor(colors.gray)
   print "Withdraw"
  putin()
    rednet.send(tonumber(id), "withdraw")
rednet.send(tonumber(id), input)
cid, funds = rednet.receive(2)
   if funds == "no" then
   print "Unsufficant Funds!"
   sleep(2)
   term.clear()
   return bank()
   else
   print "Withdrawn!"
   sleep(2)
   term.clear()
   return bank()
   end
   elseif X == 9 and Y == 12 and button == 1 then
   cp(1,7)
   term.setBackgroundColor(colors.gray)
   print "Deposit"
   putin()
  
	   rednet.send(tonumber(id), "deposit")
    rednet.send(tonumber(id), input)
    print "Deposited!"
    sleep(1.5)
    bank()
  elseif X == 9 and Y == 13 and button == 1 then
	  rednet.send(tonumber(id), "balance")
		    cip, bal = rednet.receive(2)
    print("Balance: "..bal)
    print "Press Any Key"
    event = os.pullEvent("key")
    return bank()
    elseif X == 9 and Y == 14 and button == 1 then
    print "From"
    print "Press Any Key"
    event = os.pullEvent("key")
    putin()
	    rednet.send(tonumber(id), "transfer-from")
		   rednet.send(tonumber(id), input)
	 cid, result = rednet.receive(2)
	 if result == "no" then
	    print "From Account Doesn't Exist!"
	 sleep(2)
	 return bank()
	 else
    print "To"
    print "Press Any Key"
    event = os.pullEvent("key")
    end
  
    putin()
	 
	 rednet.send(tonumber(id), "transfer-to")
		   rednet.send(tonumber(id), input)
	  print "How Much Money"
    print "Press Any Key"
    event = os.pullEvent("key")
    putin()
	  rednet.send(tonumber(id), tonumber(input))
	 cid, result = rednet.receive(2)
	 if result == "no" then
	    print "To Account Doesn't Exist!"
	 sleep(2)
	 return bank()
	 elseif result == "un" then
	 print "Failed To Transfer Funds Unsuffient!"
	 sleep(2)
	 bank()
	 else
	 print "Transfer Successful!"
	 sleep(2)
	 return bank()
	 end
	
   elseif X == 9 and Y == 15 and button == 1 then 
   rednet.send(tonumber(id), "logout")
   sleep(1)
   basic()
end
end
end
function basic()
term.setBackgroundColor(colors.black)
  term.clear()
  term.setCursorPos(10,1)
  term.setBackgroundColor(colors.blue)
  print " Kcraft Bank		  "
  term.setCursorPos(31,1)
  term.setBackgroundColor(colors.red)
  print "X"
  term.setBackgroundColor(colors.lightBlue)
  term.setCursorPos(10,2)
  print "					  "
  term.setCursorPos(10,3)
  print "	 Username:	    "
  term.setCursorPos(10,4)
  print "					  "
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(11,4)
  print "				   "
  term.setCursorPos(10,5)
  term.setBackgroundColor(colors.lightBlue)
  print "	 Password:	    "
  term.setCursorPos(10,6)
  print "					  "
  bcolor(colors.lightGray)
  cp(11,6)
  print "				   "
  bcolor(colors.lightBlue)
  term.setCursorPos(10,7)
  print "					  "
  -- Buttons --
  --Create Account--
   bcolor(colors.blue)
  cp(10,11)
  print "					  "
  cp(10,12)
  print "    Create Account    "
  cp(10,13)
  print "					  "
-- Login ---
  bcolor(colors.green)
  cp(10,8)
  print "					  "
  cp(10,9)
  print "	    LOGIN		 "
  cp(10,10)
  print "					  "
  -- Delete Account --
    bcolor(colors.red)
  cp(10,14)
  print "					  "
  cp(10,15)
  print "    Delete Account    "
  cp(10,16)
  print "					  "
  ----- CLICKABLE -------------
  main = true
while main do
local event, button, X, Y = os.pullEvent("mouse_click")
if X == 31 and Y == 1 and button == 1 then
main = false
return
end

   if X >=10 and X <=32 and Y >=8 and Y <=10 and button == 1 then -- Login
   if user == "" and pass == "" then
   print "Cannot Login With Nil Value!"
   sleep(1.2)
   basic()
   else
	  rednet.send(tonumber(id), "login")
   rednet.send(tonumber(id), user)
   rednet.send(tonumber(id), pass)
   cid, access = rednet.receive(3)
	 if access == "Denied" then
   print "Login Failed!"
   rednet.send(tonumber(id), "dont")
   sleep(2)
   return basic()
   elseif access == "Granted" then
   id, mon = rednet.receive()
   bank()
   elseif access == "no" then
   print "No Such User"
   sleep(2)
   basic()
   end
   end
   end
  
  if X >=10 and X <=32 and Y >=11 and Y <=13 and button == 1 then -- Create Account
    ain()
   rednet.send(tonumber(id), "creA")
   rednet.send(tonumber(id), user)
    rednet.send(tonumber(id), pass)
    cid, result = rednet.receive(2)
    if result == "no" then
    print "Account Already Exists!"
    sleep(2)
	 basic()
    else
    print "Account Created!"
    sleep(2)
    basic()
    end
    end
   
   
    if X >=10 and X <=32 and Y >=14 and Y <=16 and button == 1 then -- Delete Account
	  ain()
   rednet.send(tonumber(id), "delA")
   rednet.send(tonumber(id), user)
    rednet.send(tonumber(id), pass)
    cid, result = rednet.receive(2)
    if result == "no" then
    print "Account Doesn't Exist!"
    sleep(2)
   basic()
    elseif result == "invalid" then
    print "Incorrect Password!"
    sleep(2)
    basic()
   
    else
    print "Account Deleted!"
    sleep(2)
   basic()
    end
    end
   
	  if X >=11 and X <=30 and Y ==4 and button == 1 then -- user/pass
	   cp(11,4)
    bcolor(colors.lightGray)
    print "				   "
    cp(11,6)
	 bcolor(colors.lightGray)
    print "				   "
    cp(11,4)
   
    user = read()
   
    cp(11,6)
   
    pass = read("*")
    end
  end
  end
-- Serverconnect --
  rednet.send(tonumber(id), "connect")
  cid, message = rednet.receive(2)
 
  if message == "Hello" then
  basic()
  else
  error("Cannot Connect To Server: "..id.." Please Edit Config File Server ID")
  end
-- /serverconnect --

Server - The One Thats Giving Me an Error
Spoiler

rednet.open("top")
function serve()
while true do
id, mes = rednet.receive()
  if mes == "connect" then
  rednet.broadcast("Hello")
elseif mes == "withdraw" then
id, money = rednet.receive()
file = fs.open(cuser,"r")
p = file.readLine()
m = file.readLine()
file.close()
if m < money then
rednet.send(tonumber(id), "no")
print(id.." Made Invalid/Failed Withdraw From Account: "..cuser)
else
m = m - money
file = fs.open(cuser,"w")
file.writeLine(cpass)
file.writeLine(m)
file.close()
print(id.." Withdrew: "..money.." KCredits From Account: "..cuser)
end
elseif mes == "deposit" then
id, money = rednet.receive()
file = fs.open(cuser,"r")
p = file.readLine()
m = file.readLine()
file.close()
m = m + money
file = fs.open(cuser,"w")
file.writeLine(cpass)
file.writeLine(m)
file.close()
d = money
print(id.." Deposited "..d.." KCredits To Account: "..cuser)
elseif mes == "logout" then
print(id.." Logged Out Of Account: "..cuser)

elseif mes == "balance" then
file = fs.open(cuser, "r")
non = file.readLine()
mon = file.readLine()
file.close()
rednet.send(tonumber(id), mon)
print(id.." Checked Balance For Account: "..cuser)
elseif mes == "transfer-from" then
id, tf = rednet.receive()
if fs.exists(tf) then
rednet.send(tonumber(id), "yeah its here continue!")
else
rednet.send(tonumber(id), "no")
print(id.." Has entered invalid account with FROM Transaction")
end
elseif mes == "transfer-to" then
id, trt = rednet.receive()
id, value = rednet.receive()
if fs.exists(tf) then
file = fs.open(tf,"r")
non = file.readLine()
tranf = file.readLine()
file.close()
file = fs.open(trt,"r")
non2 = file.readLine()
trant =file.readLine()
file.close()
if tonumber(tranf) < tonumber(value) then
rednet.send(tonumber(id), "un")
print(id.." Tryed To Preform Transaction With "..tf.." But "..tf.." Had Unsuffient Funds! "..tranf.." - "..value)
else
mts = tranf - tonumber(value)
mta = tarnt + tonumber(value)
file = fs.open(tf,"w")
file.writeLine(non)
file.writeLine(mts)
file.close()
file = fs.open(trt,"w")
file.writeLine(non2)
file.writeLine(mta)
file.close()
print(id.." Made Transaction From "..tf.." To "..trt.." Amount: "..value)
end
else
end
elseif mes == "login" then
id, user = rednet.receive()
id, pass = rednet.receive()
if fs.exists(user) then
file = fs.open(user,"r")
cpass = file.readLine()
mon = file.readLine()
file.close()
if pass == cpass then
    rednet.broadcast("Granted")
print(id.." Logged Into Account: "..user)
   rednet.broadcast(mon)
   cuser = user
   cpass = pass
   else
   rednet.broadcast("Denied")
   print(id.." Failed To Login Into Account: "..user)
   end
else
rednet.broadcast("no")
print(id.." Tryed To Login To Non Existing Account: "..user)
end
elseif mes == "creA" then
id, creuser = rednet.receive()
id, crepass = rednet.receive()
if fs.exists(creuser) then
rednet.broadcast("no")
print(id.." Tryed To Create Existing Account: "..creuser)
else
file = fs.open(creuser,"w")
file.writeLine(crepass)
file.writeLine("0")
file.close()
rednet.broadcast("done")
print(id.." Created Account: "..creuser)
end
elseif mes == "delA" then
id, deluser = rednet.receive()
id, delpass = rednet.receive()
if fs.exists(deluser) then
file = fs.open(deluser,"r")
cdelpass = file.readLine()
file.close()
  if delpass == cdelpass then
    fs.move(deluser, "/."..deluser)
rednet.broadcast("done")
print(id.." Deleted/Moved Account: "..deluser)
  else
  rednet.broadcast("invalid")
   print(id.." Tryed To Deleted Account: "..deluser)
  end
 
else
rednet.broadcast("no")
print(id.." Tryed To Deleted Non Existing Account: "..deluser)
end
end
end
end
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setCursorPos(1,1)
print "Bank Information Below"
serve()
Bomb Bloke #2
Posted 31 October 2013 - 06:06 PM
Line 75 doesn't attempt to perform any mathematics. Please double check the error, and if you have an indented version of your code, put it on pastebin or similar.
Lewisk3 #3
Posted 31 October 2013 - 08:37 PM
lol just fixed the error i was spelling the variable wrong
how do i delete this topic?