Advertisement
MrRobar35

7sg

Dec 9th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. local cmp = require("component")
  2. local colors = require("colors")
  3. local sides = require("sides")
  4. local unicode = require("unicode")
  5. local shell = require("shell")
  6. local inet = require("internet")
  7. local rs = cmp.redstone
  8.  
  9. local chars = {
  10.     ["1"] = {9, 10},
  11.     ['2'] = {14, 12, 11, 9, 8},
  12.     ['3'] = {14, 11, 10, 9, 8},
  13.     ['4'] = {14, 13, 9, 10},
  14.     ['5'] = {14, 13, 11, 10, 8},
  15.     ['6'] = {14, 13, 11, 10, 8, 12},
  16.     ['7'] = {10, 9, 8},
  17.     ['8'] = {14, 13, 12, 11, 10, 9, 8},
  18.     ['9'] = {14, 13, 11, 10, 9, 8},
  19.     ['0'] = {13, 12, 11, 10, 9, 8}
  20. }
  21.  
  22. local enabled = {
  23.     [1] = {},
  24.     [2] = {}
  25. }
  26.  
  27. local disp1 = sides.east
  28. local disp2 = sides.west
  29.  
  30. local function has_value (tab, val)
  31.     for index, value in ipairs(tab) do
  32.         if value == val then
  33.             return true
  34.         end
  35.     end
  36.  
  37.     return false
  38. end
  39.  
  40. function tablefind(tab,el)
  41.     for index, value in pairs(tab) do
  42.         if value == el then
  43.             return index
  44.         end
  45.     end
  46. end
  47.  
  48. local function cleanMatrix()
  49.     for i = 0, 15 do
  50.         rs.setBundledOutput(disp1, i, 0)
  51.     end
  52.  
  53.     for i = 0, 15 do
  54.         rs.setBundledOutput(disp2, i, 0)
  55.     end
  56. end
  57.  
  58. local function toMatrix(num, disp)
  59.     if unicode.len(tostring(num)) > 2 then
  60.         error("Numbers that are longer than 2 digits are not allowed.")
  61.     end
  62.  
  63.     local side
  64.     if disp == 1 then
  65.         side = disp1
  66.     elseif disp == 2 then
  67.         side = disp2
  68.     end
  69.  
  70.     numstring = tostring(num)
  71.     for i = 1, tonumber(unicode.len(numstring)) do
  72.         local char = string.sub(numstring, i, i)
  73.  
  74.         if not chars[char] then
  75.             error("Character "..char.." is unsupported")
  76.         end
  77.  
  78.         for _, v in pairs(enabled[disp]) do
  79.             if not has_value(chars[char], v) then
  80.                 rs.setBundledOutput(side, v, 0)
  81.                 table.remove( enabled[disp], tablefind(enabled[disp], v) )
  82.                 print("Removed "..tostring(v)..", char "..char)
  83.             end
  84.         end
  85.  
  86.         for _, v in pairs(chars[char]) do
  87.             if not has_value(enabled[disp], v) then
  88.                 if i == 1 then
  89.                     rs.setBundledOutput(side, v, 15)
  90.                     table.insert(enabled[disp], v)
  91.                     print("Added "..tostring(v)..", char "..char)
  92.                 elseif i == 2 then
  93.                     rs.setBundledOutput(side, v-8, 15)
  94.                     table.insert(enabled[disp], v-8)
  95.                     print("Added "..tostring(v)..", char "..char)
  96.                 end
  97.             end
  98.         end
  99.     end
  100. end
  101.  
  102. ------------------------------------------------------------------------------------
  103. cleanMatrix()
  104.  
  105. for i = 1, 4 do
  106.     toMatrix(i, 1)
  107.     os.sleep(1)
  108. end
  109.  
  110. print(require("serialization").serialize(enabled))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement