16 posts
Posted 17 June 2013 - 06:10 PM
Hi,
Im writing a program in which i need to get the current background colour. I know its probably simple but i cannot find out how to do it.
Thanks
1604 posts
Posted 17 June 2013 - 06:52 PM
You can't. There's no function to get the colors in the screen. However, you could keep track of the colors before writing them to the screen, so you can get it back later. The implementation would depend on your needs, so if you want some help with that, tell us what you're trying to do and we'll do our best to help.
7083 posts
Location
Tasmania (AU)
Posted 17 June 2013 - 06:57 PM
I don't see a command that offers this function. Best I can suggest is to track it yourself (eg, create a background-setting function that records whatever it's being changed to into a variable you can check up on later), but that won't allow you to see what colour the background was before your program started.
Edit: Whoops, ninja'd. That's what I get for opening too many tabs.
16 posts
Posted 17 June 2013 - 06:57 PM
ok, thanks! ill just keep track of it. not hard just slightly inconvenient
1610 posts
Posted 19 June 2013 - 04:52 PM
I would reccommend a custom function that switches the color and saves it:
function changeBackgroundColor( color )
currentbgcolor = color
term.setBackgroundColor(color)
end
And to get the color (as a number at least) just use currentbgcolor.
1583 posts
Location
Germany
Posted 19 June 2013 - 05:05 PM
Use something like this:
local oldBgSet = term.setBackgroundColor
local colorStack = {}
term.setBackgroundColor = function(col, tStack)
if tStack then
table.insert(tStack, col)
end
oldBgSet(col)
end
--Use it so
term.setBackgroundColor(colors.white, colorStack)
print(colorStack[#colorStack]) --to get the last colorcode
--At the end of your program
term.setBackgroundColor = oldBgSet
8543 posts
Posted 19 June 2013 - 05:58 PM
Please ignore the above two posters. Keeping track of the order you used colors in wont help you determine what the color is at a given point on the screen.
You would instead want to hook into term.setBackgroundColor (so you know which color you are currently using), term.setCursorPos (so you know where the color is going) and term.write (so you know how many characters to make that color). You'll want to use these three methods to change values in a table so that you can look up the color that's on the screen at any given set of coordinates.