svdragster

Untitled

Aug 26th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. maxX, maxY = term.getSize() -- Getting the screen size
  2.  
  3. -- Note: I had some other functions setting the current text and background colour
  4. currentTextColor = colors.white
  5. currentBackgroundColor = colors.black
  6.  
  7. function myWrite(string)
  8.     tempstring = tostring(string) -- If it's a number it becomes a string here.
  9.     local x, y = term.getCursorPos()
  10.         -- Splitting every single char and save them
  11.     for i=1, #tempstring do
  12.         save(tempstring:sub(i, i), x+i-1, y, currentTextColor, currentBackgroundColor)
  13.     end
  14.         -- Write to the screen
  15.     oldWrite(tempstring)
  16. end
  17.  
  18. function save(letter, x, y, tColor, bColor)
  19. -- Here I store the textcolour, backgroundcolour and the char into the table.
  20.     screen[y][x]["fg"] = tColor
  21.     screen[y][x]["bg"] = bColor
  22.     screen[y][x]["ch"] = letter
  23. end
  24.  
  25. -- Before I can put anything into the table, I have to create it.
  26. -- It puts spaces into every block of the screensize.
  27. for y=1, maxY do
  28.     screen[y] = {} -- Telling lua screen[y] is a table.
  29.     for x=1, maxX do
  30.         screen[y][x] = {} -- Telling lua there is a table in the table screen[y]. Tableception!
  31.         screen[y][x]["fg"] = colors.white
  32.         screen[y][x]["bg"] = colors.black
  33.         screen[y][x]["ch"] = " "
  34.     end
  35. end
  36.  
  37. oldWrite = term.write -- I want to keep the term.write. So If I would do oldWrite("Hello World!") it writes Hello World! to the screen
  38. term.write = myWrite -- Overwriting the function. Now if write() or term.write() is called, my function will be run.
Advertisement
Add Comment
Please, Sign In to add comment