Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require('component')
- local tunnel = component.tunnel
- local event = require('event')
- local serialization = require('serialization')
- local data_file = 'file.txt'
- --[[ Сериализация таблиц в файл ]]--
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- --[[ Функция формирования запроса и получения ответа ]]--
- --[[ Пояснения запросов ]]--
- -- {command='getAllStorage'} -- получить список всех вещей на складе G
- --[[====================]]--
- local function sendCommand(arr)
- local timeout = 3
- local result = {status=false}
- tunnel.send(serialization.serialize(arr))
- for i=1,3 do
- answear = {event.pull(timeout,'modem_message')}
- if answear ~= nil then
- result = serialization.serialize(answear)
- break
- end
- end
- return result
- end
- --[[ Главный код (передача команд и обработка ответа) ]]--
- function printItems(arr)
- for val,val2 in pairs(arr) do
- print(val,val2)
- end
- end
- sendCommand({command='getAllStorage'})
- while true do
- local evnt = {event.pull(0)}
- if evnt[1] == 'key_up' then
- if tonumber(event[4]) == 34 then
- answear = sendCommand({command='getAllStorage'})
- printItems(answear)
- end
- elseif evnt[1] == 'modem_message' then
- local message = serialization.unserialize(evnt[6])
- printItems(message)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement