Advertisement
LDDestroier

sPrint function for Lua

Apr 8th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. --A small API made to allow a long list of text to be broken up into two lists, side by side.
  2. --This works fine on monitors.
  3.  
  4.  
  5. --Takes in string, delay between lines (seconds), line rollover X, line rollover Y, and the Y where it rolls over.
  6. function sprint(input, delay, nextLineX, nextLineY, itemThreshold)
  7.     if input == nil then
  8.         error("no input inputted, dude.")
  9.     else
  10.         if type(input) ~= "table" then
  11.             input = {input}
  12.         end
  13.         posX, posY = term.getCursorPos()
  14.         scr_x, scr_y = term.getSize()
  15.  
  16.         if nextLineX == nil then
  17.             nextLineX = 25
  18.         end
  19.         if nextLineY == nil then
  20.             nextLineY = 2
  21.         end
  22.         if itemThreshold == nil then
  23.             itemThreshold = scr_y
  24.         end
  25.  
  26.         scrollOver = 0
  27.  
  28.         itemX = posX
  29.         itemY = posY
  30.  
  31.         startX = posX
  32.         startY = posY
  33.  
  34.         itemXPosses = {}
  35.         itemYPosses = {}
  36.  
  37.         doesntFit = false
  38.  
  39.         for a = 1, #input do
  40.             if input[a] ~= nil and doesntFit == false then
  41.                 if itemY >= itemThreshold then
  42.                     scrollOver = scrollOver + 1
  43.                     itemX = startX + (nextLineX * scrollOver)
  44.                     itemY = nextLineY
  45.                 end
  46.                 term.setCursorPos(itemX,itemY)
  47.                 itemY = itemY + 1
  48.                 if delay ~= 0 and delay ~= nil then
  49.                     sleep(delay)
  50.                 end
  51.                 posX, posY = term.getCursorPos()
  52.                 scr_x, scr_y = term.getSize()
  53.                 if scr_x - posX >= nextLineX then
  54.                     write(input[a])
  55.                 else
  56.                     doesntFit = true
  57.                     return false
  58.                 end
  59.                 table.insert(itemXPosses, itemX)
  60.                 table.insert(itemYPosses, itemY)
  61.             end
  62.         end
  63.  
  64.         posX, posY = term.getCursorPos()
  65.         if doesntFit == false then
  66.             if input[#input] ~= nil then
  67.                 endPosX = posX - string.len(input[#input])
  68.             end
  69.             endPosY = posY + 1
  70.             term.setCursorPos(endPosX,endPosY)
  71.         end
  72.         return true
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement