This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gametechish's profile picture

Help with a text API

Started by gametechish, 30 May 2014 - 10:29 AM
gametechish #1
Posted 30 May 2014 - 12:29 PM
So I was writing an API for a OS I was making. Though every time I call a function from it, it clears the screen like I hoped and then says window:48: Expected number.
Here is my code:

function clearWhite()
  term.clear()
  term.setTextColor("colors.white")
end
function clearOrange()
  term.clear()
  term.setTextColor("colors.orange")
end
function clearMagenta()
  term.clear()
  term.setTextColor("colors.magenta")
end
function clearLightBlue()
  term.clear()
  term.setTextColor("colors.lightBlue")
end
function clearYellow()
  term.clear()
  term.setTextColor("colors.yellow")
end
function clearLime()
  term.clear()
  term.setTextColor("colors.lime")
end
function clearPink()
  term.clear()
  term.setTextColor("colors.pink")
end
function clearGray()
  term.clear()
  term.setTextColor("colors.gray")
end
function clearLightGray()
  term.clear()
  term.setTextColor("colors.lightGray")
end
function clearCyan()
  term.clear()
  term.setTextColor("colors.cyan")
end
function clearPurple()
  term.clear()
  term.setTextColor("colors.purple")
end
function clearBlue()
  term.clear()
  term.setTextColor("colors.blue")
end
function clearBrown()
  term.clear()
  term.setTextColor("colors.brown")
end
function clearGreen()
  term.clear()
  term.setTextColor("colors.green")
end
function clearRed()
  term.clear()
  term.setTextColor("colors.red")
end
function clearBlack()
  term.clear()
  term.setTextColor("colors.black")
end
Thanks in advance.
wieselkatze #2
Posted 30 May 2014 - 12:52 PM
Your problems are the term.setTextColor()s'.
You're calling it with a string ("colors.black" for example), but it needs a number to set the value to.
Just leave out the quotation marks, so that it looks like this:


function clearRed()
  term.clear()
  term.setTextColor(colors.red)
end

That, because colors references to the colors API (which is a table). So with the code above you are calling the color variable red in the colors table.
Edited on 30 May 2014 - 10:52 AM
gametechish #3
Posted 30 May 2014 - 12:58 PM
thank you it works now
account.username #4
Posted 31 May 2014 - 09:17 PM
It would really simple to have this as a function:


function colorClear( color )
   term.clear()
   term.setTextColor( color )
end


That way you don't have to have a separate function for each color.
gametechish #5
Posted 19 March 2015 - 03:14 AM
It would really simple to have this as a function:


function colorClear( color )
   term.clear()
   term.setTextColor( color )
end


That way you don't have to have a separate function for each color.
I was trying to make it more simple for people. I still use this API to this day in almost all my projects that use GUIs. In fact I recently used it in a project . I should clean it up though.