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

Startup:68: Attempt To Call Number

Started by GhostOmar, 05 October 2013 - 02:38 AM
GhostOmar #1
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.

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
LBPHacker #2
Posted 05 October 2013 - 05:23 AM
You set read to 0 (you should use locals, by the way), and then you call it somewhere. Don't assign read to anything. Same with next - it's a global function. Although you don't use it, I highly recommend not to assign it to anything.
GhostOmar #3
Posted 06 October 2013 - 05:31 AM
Can you suggest a solution I dont understand what you mean
theoriginalbit #4
Posted 06 October 2013 - 06:17 AM
Ok so the problem is that in several places throughout your code you're doing this

read = 5 --# or some number
Note: you also do the same with next
you then go on to do the following

pincode = read("*")
where you're trying to get user input. however the problem comes about that you just changed the read variable not to be the user input function anymore, but instead a number, thus you need to be more careful of your variable naming, making sure never to have the same names as any default function. To fix just go an change all the instances of your read variable to some other name. while you're at it also change all the next variables to something else just incase you need to write a generic-for loop since it uses next.
GhostOmar #5
Posted 06 October 2013 - 02:53 PM
Thanks ill try what you suggested tommorrow I see the problem.