Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ multi-colored on screen table

multi-colored on screen table

Posting of new messages is disabled at present.

Refresh page


Posted by Norbert   USA  (61 posts)  Bio
Date Mon 17 Apr 2006 08:22 AM (UTC)
Message
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

Norbert

-Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens
It's a dumb question... skip it.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 17 Apr 2006 09:39 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Norbert   USA  (61 posts)  Bio
Date Reply #2 on Tue 18 Apr 2006 05:20 AM (UTC)
Message
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?

Norbert

-Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens
It's a dumb question... skip it.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 18 Apr 2006 07:34 AM (UTC)
Message
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))


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Norbert   USA  (61 posts)  Bio
Date Reply #4 on Tue 18 Apr 2006 03:37 PM (UTC)
Message
Thanks you. Using table.insert and unpack worked out great.

Norbert

-Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens
It's a dumb question... skip it.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,687 views.

Posting of new messages is disabled at present.

Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.