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

program freezing no error message

Started by TR1T0N_, 27 December 2013 - 12:14 PM
TR1T0N_ #1
Posted 27 December 2013 - 01:14 PM
Hello, im currently creating a banking system and i have a problem that is when i setup the programs on the systems and run the file it works the first time around but on the second time round it just freezes and the last function it executes is on line 25 on the atm and then does nothing. the pcs are put in a formation like this
pc | id
mainserver = 4
firewall = 5
atm = 9

mainserver -> wired modem -> firewall -> wireless modem -> atm

the programs are still in development and dont have guis and they are not very efficient and the transfering function is not in the program yet here are the programs

atm software
Spoiler

function startup()
print("1")
rednet.open("top")
print("please enter your disk")
local event, param1 = os.pullEvent()
if event == "disk"
then
request()
else
print("error")
startup()
end
end
function disk()
print("2")
h = fs.open("disk/keycode", "r")
request()
end
function request()
print("3")
rednet.send(5, "request")
keycode()
end
function keycode()
print("4")
h = fs.open("/disk/keycode", "r")
code = h.readAll()
h.close()
rednet.send(5, code)
var1, var2, var3 = rednet.receive()
print(var1..var2..var3)
if var2 == "auth" then
pin()
else
deny()
end
end
function pin()
print("5")
pin = read("*")
rednet.send(5, pin)
var1, var2, var3 = rednet.receive()
if var2 == "auth" then command() else denied()
end
end
function command()
state = true
print("6")
while state == true do
print("command list")
print("------------")
print("balance")
print("withdraw")
print("logout")
cmd = read()
if cmd == "logout" then logout()
elseif cmd == "balance" then balance()
elseif cmd == "withdraw" then withdraw()
elseif cmd == "transfer" then transfer()
else print("command error")
end
end
end
function logout()
print("7")
rednet.send(5, logout)
state = false
print("please remove your disk")
sleep(5)
startup()
end
function balance()
print("8")
rednet.send(5, "check balance")
var1, var2 = rednet.receive()
print("your balance is "..var2)
end
function withdraw()
print("9")
rednet.send(5, "withdraw")
print("how much do you want to withdraw")
ammount = read()
rednet.send(5, ammount)
var3, var4 = rednet.receive()
print(var4)
command()
end
function deny()
print("10")
print("an error occured")
sleep(3)
os.reboot()
end
startup()

mainserver
Spoiler

function load()
print("load")
rednet.open("back")
print("activating server")
get()
end
function get()
print("get")
var1, var2, var3 = rednet.receive()
print(tostring(var1)..tostring(var2)..tostring(var3))
if var2 == "request" then request() else deny()
end
endfunction request()
print("request")
var4, var5, var6 = rednet.receive()
print(tostring(var4)..tostring(var5)..tostring(var6))
if fs.exists("usernames/"..tostring(var5)) == true then
pin()
else
deny()
end
end
function pin()
print("pin")
rednet.send(var1, "auth")
var7, var8, var9 = rednet.receive()
print(var7..var8..var9)
h = fs.open("userpins/"..tostring(var5).."/pin", "r")
pinno = h.readAll()
h.close()
if var8 == pinno then auth() else deny()
end
endfunction auth()
print("auth")
rednet.send(var7,"auth")
command()
end
function command()
state = true
print("command")
while state == true do
var10, var11, var12 = rednet.receive()
print(tostring(var10)..tostring(var11)..tostring(var12))
if var11 == "check balance" then checkbalance()
elseif var11 == "withdraw" then withdraw()
  elseif var11 == "transfer" then transfer()
   elseif var11 == "logout" then logout()
  end
end
endfunction checkbalance()
print("checkbalance")
h = fs.open("userbalance/"..tostring(var5).."/balance", "r")
bal = h.readAll()
rednet.send(var10, bal)
end
function withdraw()
print("withdraw")
h = fs.open("userbalance/"..tostring(var5).."/balance", "r")
bal = h.readAll()
h.close()
var13, var14, var15 = rednet.receive()
print(tostring(var13)..tostring(var14)..tostring(var15))
curbal = bal - var14
h = fs.open("userbalance/"..tostring(var5).."/balance", "w")
h.write(tostring(curbal))
h.close()
rednet.send(tostring(var13), tostring(var14).." has been deducted you current balance is "..tostring(curbal))
endfunction transfer()
print("transfer")
end
function logout()
print("logout")
state = false
get()
endfunction deny()
print("deny")
rednet.send(var1, "denied")
end
load()

firewall
Spoiler

realid = 5
function spoof(nID)
local getID = os.getComputerID -- Backing up the old function
os.getComputerID = function(nID) -- Overriding it
	return nID or getID() -- Returning the fake id or the regular computer ID
end
endfunction unspoof()
print("end spoof")
  spoof(5)
end
--firewall start
rednet.open("top")
rednet.open("back")
print("1")
while true do
rednet.open("top")
rednet.open("back")
var1, var2, var3 = rednet.receive()
print("id = "..tostring(var1))
print("msg = "..tostring(var2))
print("distance = "..tostring(var3))
print("2")
if var1 == 9  then
rednet.close("top")
rednet.open("back")
print("4")
spoof(var1)
print("5")
rednet.send(4, var2)
print("6")
elseif var1 == 4 then
rednet.close("back")
rednet.open("top")
print("7")
print("8")
spoof(var1)
print("9")
rednet.send(9, var2)
print("10")
else
rednet.send(var1, "deny")
print("11")
end
end
any help provided would be much appreciated and sorry for my horrible formatting
Edited on 27 December 2013 - 01:11 PM
RoD #2
Posted 03 April 2014 - 10:06 PM
as i can see the line 25 is when you try to send a message to the computer #5 . Maybe the computer #5 isnt running a rednet receiver.
Bomb Bloke #3
Posted 03 April 2014 - 10:37 PM
Odds are it's getting stuck on line 30:

var1, var2, var3 = rednet.receive()

If no message is received, it'll wait here indefinitely.
guesswhat123212 #4
Posted 05 April 2014 - 04:06 AM
Odds are it's getting stuck on line 30:

var1, var2, var3 = rednet.receive()

If no message is received, it'll wait here indefinitely.

change rednet.receive() to rednet.receive(3) and it will timeout after 3 seconds, that might help you out.