multi-colored on screen table

Posted by Norbert on Mon 17 Apr 2006 08:22 AM — 5 posts, 19,915 views.

USA #0
I'm trying to make a table that I can look at on the screen and I want the border to be one color while the actual data I want to be a different color. This is from the help on colournote.

ColourNote ("red", "blue", "Hello there ",
            "white", "green", "everyone")

I modified my script to 'colorize' the table. Which is produces a string like the one above to match my table. The problem is that colournote(line) will not work even though I've made sure that line is composed of 3 args all sets of 3 are separated by commas for everything I'm wanting to send to colournote. Am I doing something wrong? Or is there an easier way to get this accomplished?

function init_table(name, output, wild)
   local r, c

   filled = {}

   for r = 1, 4 do
      filled[r] = {}
      for c = 1, 15 do
         filled[r][c] = "   "
      end --for
   end --for
   colournote("red", "", "Table ready to be filled.")
end --init_table

function colorize(array)
   array = "\"" .. table.concat(array, "\", \"") .. "\""
   return array --the 3 agr for colournote in quotes
end --colorize

function print_table(name, output, wild)
   local i, r, c, space, tmp1, tmp2, tmp3, tmp4, line

   rows = utils.split ("A,B,C,D", ",")
   cols = utils.split ("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15", ",")

   space = "\n"
   for i = 1, 63 do
      space = space .. "-"
   end --for
   space = space .. "\n"
   tmp1 = { "green", "", space } --border between rows
   tmp2 = { "green", "", "|" } --border between columns
   line = colorize(tmp1)

   for r = 1, 4 do
      tmp3 = { "white", "", rows[r] }
      line = line .. ", " .. colorize(tmp2) .. ", " .. colorize(tmp3) .. ", " .. colorize(tmp2)
      for c = 1, 15 do
         tmp4 = { "white", "", filled[r][c] }
         line = line .. ", " .. colorize(tmp4) .. ", " .. colorize(tmp2)
      end -- for
      line = line .. ", " .. colorize(tmp1)
   end --for
   colournote(line)
end --print_table
Australia Forum Administrator #1
What is the error or problem exactly? ColourNote is case-sensitive for a start, you are using: colournote.

Second, you seem to be building up a string, and effectively doing this:

colournote("red, blue, Hello there ")

You need 3 arguments, not 1 argument with 3 things inside that with commas in it.
USA #2
This is the error I get.

Error number: 0
Event: Run-time error
Description: [string "Script file"]:69: bad argument #3 to `ColourNote' (string expected, got no value)
stack traceback:
[C]: in function `ColourNote'
[string "Script file"]:69: in function `print_table'
Called by: Function/Sub: print_table called by alias
Reason: processing alias ""


I think you're right the
ColourNote(""green", "", "blah", "white", "", "blah"")

is messing it up. Is there a way to get create the line without it being a string?
Australia Forum Administrator #3
If you want to build up the arguments to ColourNote on the fly, you are better off adding to a table (with table.insert for instance) and then using unpack to get them back as individual arguments. This example works:


t = { "white", "blue", "hi", "white", "green", "there" }

ColourNote (unpack (t))

USA #4
Thanks you. Using table.insert and unpack worked out great.