Posted 05 October 2013 - 04:38 AM
Hello, I have been writing a program that has a virtual credit system which allows users to withdraw and deposit credit using 1 computer. It works fine only until I select log out which will run the loop again which starts at the Pincode: then it runs an error that doesn't run the first time this code is run which is startup:68: attempt to call number
I have no clue why, tried to Google the problem, and tried to solve it with alternate solutions though it just didn't work.
I have no clue why, tried to Google the problem, and tried to solve it with alternate solutions though it just didn't work.
account = {}
account[0] = "0000"
account[1] = "1111"
account[2] = "2222"
account[3] = "3333"
balance = {}
balance[0] = 10
balance[1] = 10
balance[2] = 10
balance[3] = 10
totalBalance = 0
pincode = ""
next = 0
while next == 0 do
redstone.setOutput("bottom",true)
term.clear()
term.setCursorPos(1,1)
print("This ATM is locked.")
print("Please contact the administrator.")
term.setCursorPos(1,4)
pincode = read("*")
if pincode == "123456"
then
term.clear()
term.setCursorPos(1,1)
print("Amount of credit in the ATM:")
while next == 0 do
term.setCursorPos(1,3)
print(totalBalance)
event, key = os.pullEvent("key")
if key == 203 and totalBalance > 0
then
term.setCursorPos(1,3)
print(" ")
totalBalance = totalBalance-1
end
if key == 205 and totalBalance < 6336
then
term.setCursorPos(1,3)
print(" ")
totalBalance = totalBalance+1
end
if key == 28
then
next = 1
end
end
else
print("Invalid pincode!")
sleep(1)
end
end
next = 0
while next == 0 do
while next == 0 do
a = 0
term.clear()
term.setCursorPos(1,1)
print("Pincode:")
term.setCursorPos(1,3)
pincode = read("*")
while a < 4 and next == 0 do
if pincode == account[a]
then
next = 1
end
a = a+1
end
if a < 4
then
a = a-1
next = 1
else
print("Invalid pincode!")
sleep(1)
next = 0
end
end
next = 0
key = 0
while next == 0 do
menu = 4
term.clear()
term.setCursorPos(1,1)
print("User "..a)
print("Balance "..balance[a])
term.setCursorPos(1,4)
print("*")
term.setCursorPos(3,4)
print("Withdraw")
term.setCursorPos(3,5)
print("Deposit")
term.setCursorPos(3,6)
print("Logout")
while next == 0 do
event, key = os.pullEvent("key")
if key == 200 and menu > 4
then
menu = menu-1
end
if key == 208 and menu < 6
then
menu = menu+1
end
if key == 28
then
next = 1
end
term.setCursorPos(1,menu-1)
print(" ")
term.setCursorPos(1,menu+1)
print(" ")
term.setCursorPos(1,menu)
print("*")
end
next = 0
read = 0
term.clear()
term.setCursorPos(1,1)
if menu == 4 or menu == 5
then
print("User "..a)
print("Balance "..balance[a])
term.setCursorPos(1,4)
end
if menu == 4
then
print("How much would you like to withdraw?")
while next == 0 do
term.setCursorPos(1,6)
print(read)
event, key = os.pullEvent("key")
if key == 203 and read > 0
then
term.setCursorPos(1,6)
print(" ")
read = read-1
end
if key == 205 and read < balance[a]
then
term.setCursorPos(1,6)
print(" ")
read = read+1
end
if key == 28
then
next = 1
end
end
next = 0
if read <= totalBalance
then
balance[a] = balance[a]-read
totalBalance = totalBalance-read
print("Transaction succesful")
else
print("Transaction failed")
end
sleep(1)
end
if menu == 5
then
print("How much would you like to deposit?")
while next == 0 do
term.setCursorPos(1,6)
print(read)
event, key = os.pullEvent("key")
if key == 203 and read > 0
then
term.setCursorPos(1,6)
print(" ")
read = read-1
end
if key == 205 and read < 6336-totalBalance
then
term.setCursorPos(1,6)
print(" ")
read = read+1
end
if key == 28
then
next = 1
end
end
next = 0
balance[a] = balance[a]+read
totalBalance = totalBalance+read
print("Transaction succesful")
end
sleep(1)
if menu == 6
then
next = 1
end
end
next = 0
end