Posted 02 February 2014 - 01:35 PM
So, after I leave my world, then go back in, my programs seem to get stuck at anything related to modems. If I break my modem and replace it, the program works again. I have absolutely no idea why this is happening. Does anyone know of this bug (if it is a bug) and any way to fix it?
Thanks, Zeoic
ATM CODE
BANK SERVER CODE
Thanks, Zeoic
ATM CODE
Spoiler
local m = peripheral.wrap("monitor_0")
local modem = peripheral.wrap("left")
local accbal = 0
local straccbal = "0"
function back()
m.setBackgroundColor(colors.white)
m.clear()
m.setTextColor(colors.black)
end
function swipe()
m.setCursorPos(2,2)
m.write("Swipe an")
m.setCursorPos(2,3)
m.write("Interact Card")
m.setCursorPos(2,4)
m.write("To Continue")
m.setCursorPos(14,5)
m.write("VVV")
end
function balance()
modem = peripheral.wrap("left")
print("balance")
acc = string.sub(cardnumber, 10, 12)
print(acc)
modem.transmit(1000,1000,acc)
sleep(0.01)
modem.open(1000)
balancetest = true
while balancetest do
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "modem_message" then
accbal = tonumber(p4)
straccbal = p4
balancetest = false
end
sleep(0.01)
end
end
function withdraw()
balance()
modem = peripheral.wrap("left")
print("withdraw")
acc = string.sub(cardnumber, 10, 12)
print(acc)
modem.transmit(1000,1001,acc..wamount)
sleep(0.1)
modem.open(1000)
withdrawtest = true
while withdrawtest do
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "modem_message" and p4 == "true" then
sleep(0.1)
back()
m.setBackgroundColor(colors.white)
m.setCursorPos(3,2)
m.write("Depositing Gold")
m.setCursorPos(3,5)
m.write("VVV")
for i=1, wamount, 1 do
rs.setOutput("front",true)
sleep(0.1)
rs.setOutput("front", false)
sleep(0.1)
end
os.reboot()
withdrawtest = false
elseif e == "modem_message" and p4 == "funds" then
--Insufficient Funds
sleep(0.1)
back()
basicpage()
m.setBackgroundColor(colors.white)
m.setCursorPos(1,2)
m.write("Insufficient Funds")
while true do
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "monitor_touch" and p2 >= 18 and p3 == 1 then
os.reboot()
end
sleep(0.01)
end
else
-- unknown error
os.reboot()
end
sleep(0.01)
end
end
function basicpage()
m.setBackgroundColor(colors.white)
m.setCursorPos(2,5)
m.write("#: *** **** "..string.sub(cardnumber,10,12))
m.setBackgroundColor(colors.red)
m.setCursorPos(18,1)
m.write("X")
end
back()
swipe()
while true do
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "mag_swipe" and string.match(p1, "ICard") then
var1, var2 = string.find(p1, "ICard")
cardnumber = string.sub(p1,var2+1,var2+12)
back()
m.setCursorPos(2,2)
m.setBackgroundColor(colors.lightGray)
m.write(" ")
m.setBackgroundColor(colors.white)
m.write(" Withdraw")
m.setCursorPos(2,3)
m.setBackgroundColor(colors.gray)
m.write(" ")
m.setBackgroundColor(colors.white)
m.write(" Check Balance")
print(cardnumber)
basicpage()
while true do
e, p1, p2, p3, p4 ,p5 = os.pullEvent()
if e == "monitor_touch" and p2 == 18 and p3 == 1 then
os.reboot()
elseif e== "monitor_touch" and p2 == 2 and p3 == 2 then
-- withdraw
back()
basicpage()
m.setBackgroundColor(colors.white)
m.setCursorPos(6,1)
m.write("Max:$100")
m.setBackgroundColor(colors.white)
m.setCursorPos(2,2)
m.write("Withdraw Amount:")
m.setBackgroundColor(colors.lime)
m.setCursorPos(8,4)
m.write("DONE")
withtrue = true
witham = 0
while withtrue do
m.setBackgroundColor(colors.white)
m.setCursorPos(8,3)
m.clearLine()
m.write("$"..witham)
m.setCursorPos(1,3)
m.setBackgroundColor(colors.red)
m.write("-10")
m.setCursorPos(5,3)
m.setBackgroundColor(colors.red)
m.write("-")
m.setCursorPos(14,3)
m.setBackgroundColor(colors.green)
m.write("+")
m.setCursorPos(16,3)
m.setBackgroundColor(colors.green)
m.write("+10")
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "monitor_touch" and p2 == 5 and p3 == 3 then
print("-")
if witham <= 0 then
else
witham = witham-1
end
elseif e == "monitor_touch" and p2 == 14 and p3 == 3 then
print("+")
if witham >= 100 then
else
witham = witham+1
end
elseif e == "monitor_touch" and p2 >= 16 and p2 <= 18 and p3 == 3 then
print("+10")
if witham >= 91 then
else
witham = witham+10
end
elseif e == "monitor_touch" and p2 >= 1 and p2 <= 3 and p3 == 3 then
print("-10")
if witham <= 9 then
else
witham = witham-10
end
elseif e == "monitor_touch" and p2 >= 18 and p3 == 1 then
os.reboot()
elseif e == "monitor_touch" and p2 >= 8 and p2 <= 11 and p3 == 4 then
--DONE
sleep(0.5)
m.clear()
back()
basicpage()
m.setBackgroundColor(colors.white)
m.setCursorPos(3,2)
m.write("Withdraw $"..witham.."?")
m.setCursorPos(4,3)
m.setBackgroundColor(colors.red)
m.write("No")
m.setCursorPos(13,3)
m.setBackgroundColor(colors.green)
m.write("Yes")
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "monitor_touch" and p2 >= 4 and p2 <= 5 and p3 == 3 then
os.reboot()
elseif e == "monitor_touch" and p2 >= 13 and p2 <= 15 and p3 == 3 then
--ACTUAL WITHDRAWL
wamount = witham
withdraw()
elseif e == "monitor_touch" and p2 >= 18 and p3 == 1 then
os.reboot()
end
end
end
elseif e== "monitor_touch" and p2 == 2 and p3 == 3 then
-- Check Balance
balance()
print(accbal)
back()
basicpage()
m.setBackgroundColor(colors.white)
m.setCursorPos(2,2)
m.write("Current Balance:")
x = string.len(straccbal)
x = x/2-1
x = 9-x
m.setCursorPos(x,3)
m.write("$"..straccbal)
end
sleep(0.01)
end
end
sleep(0.1)
end
BANK SERVER CODE
Spoiler
local modem = peripheral.wrap("left")
modem.open(1000)
while true do
e,p1,p2,p3,p4,p5 = os.pullEvent()
if e == "modem_message" and p3 == 1000 then
--check balance
print("===================================================")
print("Account: "..p4)
file = fs.open(p4,"r")
bal = file.readAll()
modem = peripheral.wrap("left")
sleep(0.1)
modem.transmit(1000, 1000, bal)
print("Balance: "..bal)
elseif e == "modem_message" and p3 == 1001 then
--withdrawl
print("===================================================")
print("Account: "..string.sub(p4,1,3))
file = fs.open(string.sub(p4,1,3),"r")
bal = file.readAll()
print("Old Balance: "..bal)
print("Withdrawl Amount: "..string.sub(p4,4))
newbal = tonumber(bal)-tonumber(string.sub(p4,4))
file.close()
if newbal >= 0 then
print("New Balance: "..newbal)
file = fs.open(string.sub(p4,1,3),"w")
file.write(newbal)
file.close()
modem.transmit(1000, 1000, "true")
print("Withdrawl Completed Successfuly")
else
modem.transmit(1000, 1000, "funds")
print("Account had Insufficient Funds!")
end
end
sleep(0.01)
end
Edited on 02 February 2014 - 12:48 PM