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

Help With Banking System Error Please D:

Started by thatsimplekid, 27 January 2013 - 02:28 AM
thatsimplekid #1
Posted 27 January 2013 - 03:28 AM
Hi, please help, i have written a banking system for use on computercraft, and the programs run fine on both sides until the user enters an amount on the client. When an amount is entered an error appears on the server, saying:

serv:52: attempt to index ? (a nil value)

Please help, i have worked real hard on this, and would love to see it work, thanks in advance

thatsimplekid

http://pastebin.com/PqE0fE9Y - Server - ID:20
http://pastebin.com/UXttdgys - Client - ID:23
Orwell #2
Posted 27 January 2013 - 03:51 AM
That happens because you declared database as local inside the while loop. The variable 'database' doesn't exist outside of the loop. To fix this easily, put this at the top of your code (before the while loop):

local database
And change the definitions of database inside the loop to:

database = textutils.unserialize(file.readAll())
and

database = {
  ["ANTNCO"] = {
	pin = 1234;
	balance = 500000;
  };
  ["thatsimplekid"] = {
	pin = 8080;
	balance = 25000;
  };

So without local there. 'database' will still be local to your program, but accessible from everywhere within your program.

Edit: Also, there is a new policy on signatures. You're not supposed to have images in them anymore: http://www.computercraft.info/forums2/index.php?/topic/9810-new-signature-requirements-what/
thatsimplekid #3
Posted 27 January 2013 - 12:17 PM
That happens because you declared database as local inside the while loop. The variable 'database' doesn't exist outside of the loop. To fix this easily, put this at the top of your code (before the while loop):

local database
And change the definitions of database inside the loop to:

database = textutils.unserialize(file.readAll())
and

database = {
  ["ANTNCO"] = {
	pin = 1234;
	balance = 500000;
  };
  ["thatsimplekid"] = {
	pin = 8080;
	balance = 25000;
  };

So without local there. 'database' will still be local to your program, but accessible from everywhere within your program.

Edit: Also, there is a new policy on signatures. You're not supposed to have images in them anymore: http://www.computerc...uirements-what/

thanks, i will try it, and thanks for letting me know about signatures :D/>