Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("top")
- local disk = peripheral.wrap("bottom")
- --local tx = 1
- local rx = 0 --id serveur
- term.clear()
- term.setCursorPos(1,1)
- modem.open(rx)
- --=============================================================
- while (disk.hasData() == true) do
- local input,s,f,reply,command = os.pullEvent("modem_message")
- print("=======================")
- if command[2] == "start" then
- print(command[1],"~~~start")
- if fs.exists(command[1]) == true then
- print("path ok")
- local compte = fs.open(command[1],"r")
- local val = compte.readLine(1)
- compte.close()
- sleep(1)
- modem.transmit(reply,rx,val)
- else
- sleep(1)
- modem.transmit(reply,rx,"error")
- end
- end
- if command[2] == "add" then
- print("add")
- local compte = fs.open(command[1],"r")
- local val = compte.readLine(1)
- compte.close()
- nval = val+command[3]
- print(nval)
- local compte = fs.open(command[1],"w")
- compte.write(nval)
- compte.close()
- end
- if command[2] == "take" then
- print("take")
- local compte = fs.open(command[1],"r")
- local val = compte.readLine(1)
- compte.close()
- nval = val-command[3]
- print(nval)
- local compte = fs.open(command[1],"w")
- compte.write(nval)
- compte.close()
- end
- if command[2] == "new" then
- print("new")
- compte = fs.open(command[1],"w")
- compte.write(0)
- compte.close()
- end
- if command[2] == "transf" then
- print("transf")
- local compte = fs.open(command[1],"r")
- local val = compte.readLine(1)
- compte.close()
- nval = val-command[3]
- print(nval)
- local compte = fs.open(command[1],"w")
- compte.write(nval)
- compte.close()
- local compte = fs.open(command[4],"r")
- local val = compte.readLine(1)
- compte.close()
- nval = val+command[3]
- print(nval)
- local compte = fs.open(command[4],"w")
- compte.write(nval)
- compte.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement