Advertisement
pepeknamornik

Změna HW

Jul 2nd, 2020
2,686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. verze = "20.0802.R1"
  2. local ramCesta = "/C/system/RAM/devices/"
  3. local modemy={}
  4. local modemNum=0
  5. local pocitace={}
  6. local pocitaceNum=0
  7. local repro={}
  8. local reproNum=0
  9. local drive={}
  10. local driveNum=0
  11. local monitor={}
  12. local monitorNum=0
  13. local tisk={}
  14. local tiskNum=0
  15.  
  16. function save(table,name)
  17.     local file = fs.open(ramCesta..""..name,"w")
  18.     file.write(textutils.serialize(table))
  19.     file.close()
  20. end
  21.  
  22. function evidence()
  23.     if modemNum > 0 then
  24.     save(modemy,"modem.tmp")
  25.     end
  26.         if pocitaceNum > 0 then
  27.         save(pocitace,"computer.tmp")
  28.         end
  29.     if driveNum > 0 then
  30.     save(drive,"drive.tmp")
  31.     end
  32.         if monitorNum > 0 then
  33.         save(monitor,"monitor.tmp")
  34.         end
  35.     if tiskNum > 0 then
  36.     save(tisk,"printer.tmp")
  37.     end
  38.         if reproNum > 0 then
  39.         save(repro,"speaker.tmp")
  40.         end
  41. end
  42.  
  43. function hodnot()
  44.     if typ_zar == "modem" then
  45.     modemNum = modemNum + 1
  46.     modemy[modemNum] = pozice
  47.     elseif typ_zar == "computer" then
  48.     pocitaceNum = pocitaceNum + 1
  49.     pocitace[pocitaceNum] = pozice
  50.     elseif typ_zar == "drive" then
  51.     driveNum = driveNum + 1
  52.     drive[driveNum] = pozice
  53.     elseif typ_zar == "monitor" then
  54.     monitorNum = monitorNum + 1
  55.     monitor[monitorNum] = pozice
  56.     elseif typ_zar == "printer" then
  57.     tiskNum = tiskNum + 1
  58.     tisk[tiskNum] = pozice
  59.     elseif typ_zar == "speaker" then
  60.     reproNum = reproNum + 1
  61.     repro[tiskNum] = pozice
  62.     end
  63. end
  64.  
  65. function rozpoznat()
  66.     local q = 0
  67.     repeat
  68.         q = q+1
  69.         hledej = string.sub(device,q,q)
  70.         if (hledej==" ") then
  71.             typ_zar = string.sub(device,1,q-1)
  72.             pozice = string.sub(device,q+1,#device)
  73.             hodnot()
  74.             q = #device
  75.         end
  76.     until q == #device
  77.     cist()
  78. end
  79.  
  80. function cist()
  81.     device = data.readLine()
  82.     if device == nil then
  83.         evidence()
  84.         data.close()
  85.     else
  86.         rozpoznat()
  87.     end
  88. end
  89.  
  90. local periList = peripheral.getNames()
  91. local s = fs.open (ramCesta.."All.tmp","w")
  92.     for i = 1, #periList do
  93.     s.writeLine(peripheral.getType(periList[i]).." "..periList[i])
  94.     end
  95. s.close()
  96.    
  97. data = fs.open (ramCesta.."All.tmp","r")
  98. cist()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement