Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DELAY = 0.1
- local LOADING_BAR = "<=======================>"
- local LOADING_TEXT = "Processing"
- local LOAD = {
- LOADING_BAR,
- LOADING_TEXT,
- LOADING_BAR,
- }
- function writePos (char, x, y)
- -- moves the cursor to the given position and writes the character $char
- term.setCursorPos (x, y)
- term.write (char)
- end
- function multiSlowPrint (string_table, delay)
- -- 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
- local start_x, start_y = term.getCursorPos ()
- local size_x, size_y = term.getSize ()
- local longest_x = 0 -- we need this function to know when we have reached the end of the given strings
- for i = 1, #string_table do
- local len = #string_table [i]
- if len > longest_x then
- longest_x = len
- end
- end
- for x = 0, size_x - 1 do
- if x >= longest_x then
- term.setCursosPos (0, start_y + #string_table + 1)
- break -- if we have reached the rightmost position of our given string we want to abort the function
- end
- for y = 0, #string_table - 1 do
- 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
- if char nil == then
- char = " "
- end
- writePos (char, x, y)
- end
- sleep (delay)
- end
- end
- multiSlowPrint (LOAD, DELAY)
Add Comment
Please, Sign In to add comment