Alex1987

Untitled

Sep 15th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. local DELAY = 0.1
  2. local LOADING_BAR = "<=======================>"
  3. local LOADING_TEXT = "Processing"
  4. local LOAD = {
  5. LOADING_BAR,
  6. LOADING_TEXT,
  7. LOADING_BAR,
  8. }
  9.  
  10. function writePos (char, x, y)
  11. -- moves the cursor to the given position and writes the character $char
  12. term.setCursorPos (x, y)
  13. term.write (char)
  14. end
  15.  
  16. function multiSlowPrint (string_table, delay)
  17. -- string_table holds the strings which shall be printed slow across several lines, each string representing one line; delay is the time to wait between each step of the function
  18.  
  19. local start_x, start_y = term.getCursorPos ()
  20. local size_x, size_y = term.getSize ()
  21.  
  22. local longest_x = 0 -- we need this function to know when we have reached the end of the given strings
  23. for i = 1, #string_table do
  24. local len = #string_table [i]
  25. if len > longest_x then
  26. longest_x = len
  27. end
  28. end
  29.  
  30. for x = 0, size_x - 1 do
  31. if x >= longest_x then
  32. term.setCursosPos (0, start_y + #string_table + 1)
  33. break -- if we have reached the rightmost position of our given string we want to abort the function
  34. end
  35. for y = 0, #string_table - 1 do
  36.  
  37. local char = string_table [y + 1]:sub (x + 1, x +1) -- you can read about string indexing in Lua here http://lua-users.org/wiki/StringIndexing
  38. if char nil == then
  39. char = " "
  40. end
  41.  
  42. writePos (char, x, y)
  43.  
  44. end
  45. sleep (delay)
  46. end
  47. end
  48.  
  49. multiSlowPrint (LOAD, DELAY)
Add Comment
Please, Sign In to add comment