Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODEM_SIDE = 'top'
- sensorId = nil
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function mainScreen()
- term.setBackgroundColor(colors.black)
- clearScreen()
- term.setBackgroundColor(colors.blue)
- term.write("> ")
- width = term.getSize()
- for i=3,width do
- term.write(' ')
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(3,1)
- end
- function retreiveData()
- rednet.send(sensorId, {type='query'})
- while true do
- snd,data = rednet.receive()
- if(snd == sensorId) then
- return data
- end
- end
- end
- function processRequest(req)
- data = retreiveData()
- result = {}
- for label,val in pairs(data) do
- for slotId,content in pairs(val.Slots) do
- if(string.lower(content.Name):find(req) ~= nil) then
- result[#result+1] = val.Position
- break
- end
- end
- end
- return result
- end
- function displayResult(res)
- _,height = term.getSize()
- if(#res > 0) then
- for line = 2, math.min(#res+1, height) do
- term.setCursorPos(1,line)
- pos = res[line - 1]
- rangee = 0
- if(pos.Z == 0) then
- rangee = 2
- elseif(pos.Z > 0) then
- rangee = 1
- else
- rangee = 3
- end
- profondeur = math.floor((pos.X + 5) / 2) + 1
- hauteur = pos.Y + 8
- term.write('Rangée '..rangee..' ; profondeur '..profondeur..' ; hauteur '..hauteur)
- end
- else
- term.setCursorPos(1,2)
- term.write("Aucun résultat.")
- end
- term.setCursorPos(3,1)
- end
- function main()
- clearScreen()
- print("Loading...")
- rednet.open(MODEM_SIDE)
- os.sleep(3)
- sensorId = rednet.lookup('sensor', 'chests')
- if(sensorId == nil) then
- print("Sensor unavailable.")
- os.sleep(5)
- return
- end
- mainScreen()
- while(true) do
- term.setBackgroundColor(colors.blue)
- req = read()
- mainScreen()
- res = processRequest(req)
- displayResult(res)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement