Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("back")
- mag = peripheral.wrap("right")
- local timer
- function program()
- print("Banca di BlueCity - Ritiro da carta")
- print("\nInserire la carta")
- _, data, label = os.pullEvent("mag_swipe")
- tab = textutils.unserialize(data)
- if tab == nil or tab.credito == nil or tab.label == nil then
- print("\nCarta non valida!")
- sleep(2)
- os.reboot()
- end
- if tab.credito < 0 or tab.label ~= "BCB" then
- print("\nCarta non valida!")
- sleep(2)
- os.reboot()
- end
- print("\nCredito disponibile: "..tostring(tab.credito).." IC")
- term.write("Quanto vuoi ritirare? >> ")
- quant = read()
- if tonumber(quant) == nil or tonumber(quant) < 0 or tonumber(quant) > tab.credito then
- print("\nInserire un numero valido!")
- sleep(2)
- os.reboot()
- end
- tab.credito = tab.credito - tonumber(quant)
- timer = os.startTimer(10)
- print("\nInserire nuovamente la carta per confermare")
- while true do
- mag.beginWrite(textutils.serialize(tab), "BC Bank")
- _, k = os.pullEvent("mag_write_done")
- if _ == "key" then
- print("Annullamento in corso")
- sleep(2)
- os.reboot()
- elseif _ == "mag_write_done" then
- print("\nNuovo credito: "..tostring(tab.credito))
- modem.send(quant)
- sleep(2)
- end
- end
- end
- function timer()
- os.pullEvent("timer")
- os.reboot()
- end
- parallel.waitForAny(program, timer)
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement