Have you been wanting to use the handy dandy term.getTextColor() and term.getBackgroundColor() functions on older versions of ComputerCraft? Well, you can! And real simple too!
Simply add this code and have it run when the computer starts:
if _CC_VERSION == nil then
print("Patching term.getTextColor() and term.getBackgroundColor() in due to pre1.74 CC.")
sleep(0.1)
oldTermSetTextColor = term.setTextColor
oldTermSetBackColor = term.setBackgroundColor
currentTermGetTextColor = colors.white
currentTermGetBackColor = colors.black
function term.setTextColor(color)
oldTermSetTextColor(color)
currentTermGetTextColor = color
end
function term.setBackgroundColor(color)
oldTermSetBackColor(color)
currentTermGetBackColor = color
end
function term.getTextColor()
return currentTermGetTextColor
end
function term.getBackgroundColor()
return currentTermGetBackColor
end
end
EDIT: an explanation of how this works.
So basically, it checks if _CC_VERSION is nil (since term.getTextColor() and term.getBackgroundColor() were added at the same time as _CC_VERSION was added). If it is, it overrides the term.setTextColor and term.setBackgroundColor functions to store the colors they set in a variable (also backing up the originals so they can be called). Then, it creates two functions term.getTextColor() and term.getBackgroundColor() that access these variables and return them.
http://pastebin.com/hXymBQgc
Edited by cyanisaac, 27 August 2015 - 12:15 AM.












