Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- maxX, maxY = term.getSize() -- Getting the screen size
- -- Note: I had some other functions setting the current text and background colour
- currentTextColor = colors.white
- currentBackgroundColor = colors.black
- function myWrite(string)
- tempstring = tostring(string) -- If it's a number it becomes a string here.
- local x, y = term.getCursorPos()
- -- Splitting every single char and save them
- for i=1, #tempstring do
- save(tempstring:sub(i, i), x+i-1, y, currentTextColor, currentBackgroundColor)
- end
- -- Write to the screen
- oldWrite(tempstring)
- end
- function save(letter, x, y, tColor, bColor)
- -- Here I store the textcolour, backgroundcolour and the char into the table.
- screen[y][x]["fg"] = tColor
- screen[y][x]["bg"] = bColor
- screen[y][x]["ch"] = letter
- end
- -- Before I can put anything into the table, I have to create it.
- -- It puts spaces into every block of the screensize.
- for y=1, maxY do
- screen[y] = {} -- Telling lua screen[y] is a table.
- for x=1, maxX do
- screen[y][x] = {} -- Telling lua there is a table in the table screen[y]. Tableception!
- screen[y][x]["fg"] = colors.white
- screen[y][x]["bg"] = colors.black
- screen[y][x]["ch"] = " "
- end
- end
- 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
- 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