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

Need help with lua banking system.

Started by hotchilli, 03 December 2014 - 09:23 PM
hotchilli #1
Posted 03 December 2014 - 10:23 PM
Hi, I'm new to the forum and I have been trying to create a banking system. But I started to get this error:

bios:366: [string "Cashier"]:84: unexpected symbol

after I'd edited the file with Notepad++
Here is the code:

Spoiler
os.loadAPI("Client")
id = 8
password = 2987
Client.connect(id)
os.sleep(2)
Client.close()
term.clear()
term.setCursorPos(1,1)

--os.pullEvent = os.pullEventRaw
print"######################"
print"@@Hotchilli  Banking@@"
print"######################"
print"----------------------"
print"Please Enter Name"
user = read()
print"Please Enter Bank Code"
pass = read("*")

if tonumber(pass) == password then
print"Logging in"
else
print"Access Denied"
os.sleep(1)
os.shutdown()
end

function mainmenu()

term.clear()
term.setCursorPos(1,1)
local o = 1
end

function displayuser()
term.setCursorPos(41,1)
print(user)
term.setCursorPos(1,2)
end
options ={"Balance", "Deposit", "Withdraw", "Transfer", "New Account", "Delete Account"}
while true do
term.clear()
displayuser()
for key,value in pairs(options) do
if key == o then
print(value.." <")
else
print(value)

  end
end
local event, scancode = os.pullEvent("key")
print(tostring(scancode))
  if scancode == 200 and o > 1 then
o = o - 1
  elseif scancode == 208 and o < 7 then
  o = o + 1

   elseif scancode == 26 then
break
end
end
mainmenu()

if o == 1 then
Client.connect(id)
term.clear()
displayuser()
print("Balance")
print("----------------------")
rednet.send(contact, "Balance")
listen()
if message == "OK" then

print("Reading Card Info")
h = fs.open("disk/info", "r")
cardno = h.readLine()
rednet.send(contact,cardno)
print("Sending Information")

listen()
if message == "Pin" then
print("Pin?")
pin = read(*)
rednet.send(contact,pin)

h.close()

listen()
Balance = message
term.clear()
displayuser()
print("Balance")
print("----------------------")
print(Balance)

Client.close()
mainmenu()

elseif o == 2 then



end
end
end

Thanks in advance for any help :)/>
Edited on 06 December 2014 - 09:02 AM
ElvishJerricco #2
Posted 03 December 2014 - 10:32 PM

pin = read(*)
should be

pin = read("*")

Although you really need to be using locals and proper tab spacing.
Dragon53535 #3
Posted 03 December 2014 - 10:33 PM
Line 84 -

pin = read(*)
It's telling you incorrect symbol because you need that * to be a string

pin = read("*")

EDIT: :ph34r:/> 'd Darn you Elvish!
Edited on 03 December 2014 - 09:34 PM
hotchilli #4
Posted 03 December 2014 - 10:42 PM
Thank You so much. It works now!
hotchilli #5
Posted 03 December 2014 - 11:03 PM

pin = read(*)
should be

pin = read("*")

Although you really need to be using locals and proper tab spacing.

Also, How would I stop this loop and run 'execute()'
Spoiler

while true do
term.clear()
displayuser()
for key,value in pairs(options) do
if key == o then
print(value.." <")
else
print(value)
  end
end
local event, scancode = os.pullEvent("key")
print(tostring(scancode))
  if scancode == 200 and o > 1 then
o = o - 1
  elseif tonumber(scancode) == 208 and o < 7 then
  o = o + 1
  elseif scancode == 26 then

end
execute()
end
[CODE]
Edited on 04 December 2014 - 05:12 PM
KingofGamesYami #6
Posted 04 December 2014 - 12:17 AM
When do you want it to end? (Also, I posted in it code tags for you below)

while true do
  term.clear()
  displayuser()
  for key,value in pairs(options) do
    if key == o then
      print(value.." <")
    else
      print(value)
    end
  end
  local event, scancode = os.pullEvent("key")
  print(tostring(scancode))
  if scancode == 200 and o > 1 then
    o = o - 1
  elseif tonumber(scancode) == 208 and o < 7 then
    o = o + 1 
  elseif scancode == 26 then
    --#do nothing
  end
  execute()
end
Bomb Bloke #7
Posted 04 December 2014 - 12:20 AM
Sounds like you want the break command. When it executes, it'll jump to the bottom of whatever loop you happen to be in.
hotchilli #8
Posted 04 December 2014 - 07:08 AM
When do you want it to end? (Also, I posted in it code tags for you below)

while true do
  term.clear()
  displayuser()
  for key,value in pairs(options) do
	if key == o then
	  print(value.." <")
	else
	  print(value)
	end
  end
  local event, scancode = os.pullEvent("key")
  print(tostring(scancode))
  if scancode == 200 and o > 1 then
	o = o - 1
  elseif tonumber(scancode) == 208 and o < 7 then
	o = o + 1
  elseif scancode == 26 then
	--#do nothing
  end
  execute()
end

I wanted it to break at

elseif scancode == 26 then
	--#do nothing
  end

Sounds like you want the break command. When it executes, it'll jump to the bottom of whatever loop you happen to be in.

I've been trying to do that but i can't figure out exactly where to but the break.
Bomb Bloke #9
Posted 04 December 2014 - 02:33 PM
Did you try…?:

elseif scancode == 26 then
        break
  end
hotchilli #10
Posted 04 December 2014 - 05:59 PM
Did you try…?:

elseif scancode == 26 then
		break
  end

Here is my code

Spoiler

os.loadAPI("Client")
id = 8
password = 2987
Client.connect(id)
os.sleep(2)
Client.close()
term.clear()
term.setCursorPos(1,1)

--os.pullEvent = os.pullEventRaw
print"######################"
print"@@Hotchilli  Banking@@"
print"######################"
print"----------------------"
print"Please Enter Name"
user = read()
print"Please Enter Bank Code"
pass = read("*")

if tonumber(pass) == password then
print"Logging in"
else
print"Access Denied"
os.sleep(1)
os.shutdown()
end
function execute()
if o == 1 then
Client.connect(id)
term.clear()
displayuser()
print("Balance")
print("----------------------")
rednet.send(contact, "Balance")
listen()
if message == "OK" then

print("Reading Card Info")
h = fs.open("disk/info", "r")
cardno = h.readLine()
rednet.send(contact,cardno)
print("Sending Information")

listen()
if message == "Pin" then
print("Pin?")
pin = read("*")
rednet.send(contact,pin)

h.close()

listen()
Balance = message
term.clear()
displayuser()
print("Balance")
print("----------------------")
print(Balance)

Client.close()
mainmenu()

elseif o == 2 then



end
end
end

end
function mainmenu()

term.clear()
term.setCursorPos(1,1)
end
function displayuser()
term.setCursorPos(41,1)
print(user)
term.setCursorPos(1,2)
end
options ={"Balance", "Deposit", "Withdraw", "Transfer", "New Account", "Delete Account"}
local o = 1
while true do
term.clear()
displayuser()
for key,value in pairs(options) do
if key == o then
print(value.." <")
else
print(value)
  end
end
local event, scancode = os.pullEvent("key")
print(tostring(scancode))
  if scancode == 200 and o > 1 then
o = o - 1
  elseif tonumber(scancode) == 208 and o < 7 then
  o = o + 1
  elseif scancode == 26 then
  break
end
execute()
end

mainmenu()
I want to run execute() after I press enter (scancode 26).
Edited on 04 December 2014 - 05:00 PM
hotchilli #11
Posted 04 December 2014 - 06:33 PM
I've reorganized my code and fixed the break problem but now I get the error:
rednet:87: Expected number

I don't see the problem
If you need any more of my code please ask.

Spoiler

--APIs
os.loadAPI("Client")
--Variables
local id = 8
local o = 1
local password = 2987
options ={"Balance", "Deposit", "Withdraw", "Transfer", "New Account", "Delete Account"}
--Functions
function displayuser()
term.setCursorPos(41,1)
print(user)
term.setCursorPos(1,2)
end
function execute()
if o == 1 then
Client.connect(id)
term.clear()
displayuser()
print("Balance")
print("----------------------")
rednet.send(contact, "Balance")
listen()
if message == "OK" then

print("Reading Card Info")
h = fs.open("disk/info", "r")
cardno = h.readLine()
rednet.send(contact,cardno)
print("Sending Information")

listen()
if message == "Pin" then
print("Pin?")
pin = read("*")
rednet.send(contact,pin)

h.close()

listen()
Balance = message
term.clear()
displayuser()
print("Balance")
print("----------------------")
print(Balance)

Client.close()
mainmenu()

elseif o == 2 then



end
 end
end

end
function mainmenu()
term.clear()
term.setCursorPos(1,1)
while true do
 term.clear()
 displayuser()
 for key,value in pairs(options) do
 if key == o then
 print(value.." <")
 else
 print(value)
  end
 end
 local event, scancode = os.pullEvent("key")
 print(tostring(scancode))
  if scancode == 200 and o > 1 then
 o = o - 1
  elseif tonumber(scancode) == 208 and o < 7 then
  o = o + 1 
  elseif scancode == 26 then
  break
 end
execute()
end
end
--Code
--os.pullEvent = os.pullEventRaw
Client.connect(id)
os.sleep(2)
Client.close()
term.clear()
term.setCursorPos(1,1)

print"######################"
print"@@Hotchilli  Banking@@"
print"######################"
print"----------------------"
print"Please Enter Name"
user = read()
print"Please Enter Bank Code"
pass = read("*")

mainmenu()
KingofGamesYami #12
Posted 04 December 2014 - 06:38 PM

rednet.send(contact, "Balance")

But contact is never defined.
hotchilli #13
Posted 04 December 2014 - 07:08 PM

rednet.send(contact, "Balance")

But contact is never defined.

Contact is defined in the API but I got around that by just using the terminal number. I can change this if I am going to incorporate multiple 'servers'.
Thanks :)/>
Bomb Bloke #14
Posted 04 December 2014 - 11:13 PM
If you defined a variable called "contact" in the "Client" API, then your script would refer to that variable as "Client.contact".
hotchilli #15
Posted 05 December 2014 - 05:27 PM
If you defined a variable called "contact" in the "Client" API, then your script would refer to that variable as "Client.contact".

Ok, thanks!
hotchilli #16
Posted 06 December 2014 - 09:34 AM
If you defined a variable called "contact" in the "Client" API, then your script would refer to that variable as "Client.contact".

Also, would you be able to share a computer's files between multiple computers?
Could you do this by using wired modems as if it were a monitor?
Edited on 06 December 2014 - 08:35 AM
KingofGamesYami #17
Posted 08 December 2014 - 07:48 PM
If you defined a variable called "contact" in the "Client" API, then your script would refer to that variable as "Client.contact".

Also, would you be able to share a computer's files between multiple computers?
Could you do this by using wired modems as if it were a monitor?

You can't 'share' files, but you can tell all computers to detect when a change is made to a file and send of a rednet message with the updated file to all other computers. Or you could just use a disk in a disk drive connected to your network.