Advertisement
CelticCoder

test

Aug 7th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. rednet.open("bottom")
  2. function substringColonToSpace(inputString)
  3.     local startPos = string.find(inputString, ":")
  4.     if not startPos then
  5.         return nil, "No colon found in the input string."
  6.     end
  7.    
  8.     local endPos = string.find(inputString, " ", startPos)
  9.     if not endPos then
  10.         return nil, "No space found after the colon in the input string."
  11.     end
  12.    
  13.     return string.sub(inputString, startPos + 1, endPos - 1)
  14. end
  15.  
  16. function twoInputStrip(str)
  17.     first, second = str:match("(%S+)%s+(%S+)")
  18.     return first, second
  19. end
  20.  
  21. function getAcceptedItems()
  22.     rednet.send(0, "items please")
  23.     id, items = rednet.receive()
  24.     itemdb = {}
  25.     for _, item in pairs(items) do
  26.         temp, itemvalue = twoInputStrip(item)
  27.         table.insert(itemdb, substringColonToSpace(item) .. " - $" .. itemvalue)
  28.     end
  29.     return itemdb
  30. end
  31.  
  32. function getMonitorDirection()
  33.     local peripherals = peripheral.getNames()
  34.     for _, name in ipairs(peripherals) do
  35.         if peripheral.getType(name) == "monitor" then
  36.             return name
  37.         end
  38.     end
  39.     return nil
  40. end
  41.  
  42. function displayItems()
  43.     direction = getMonitorDirection()
  44.     if direction ~= nil then
  45.         local monitor = peripheral.wrap(direction)
  46.         monitor.clear()
  47.         itemdb = getAcceptedItems()
  48.         for i, item in pairs(itemdb) do
  49.             monitor.setCursorPos(1, i)
  50.             monitor.write(item)
  51.         end
  52.     end
  53. end
  54.  
  55. displayItems()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement