[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  A problem with a table
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

A problem with a table

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Tue 28 Aug 2007 07:15 AM (UTC)  quote  ]
Message
I am trying to have a plugin with changeable display colours. I'm having a large problem with the colour changing script though, and I can't figure out why.

function ChangeColour( sTrig, sLine, wildcards )
  print( wildcards[1].." "..wildcards[2] )
  require "tprint"
  tprint( colours )
  tprint( colourcodes )
  print( ( colours[ wildcards[1] ] or "nil" ).." "..( colourcodes[ wildcards[2] or "" ] or "nil" ) )
  if colourcodes[ wildcards[2] ] ~= nil then
    colours[ wildcards[1] ] = wildcards[2]
  else
    ColourNote( colourcodes[ "%W" ], "", wildcards[2].." is an invalid selection " )
  end
end

all the prints are just for debugging this odd problem. Here is what happens when it is run:

1 @R
1="@G"
2="@W"
"@B"="#78BCFF"
"@C"="#5AFFFF"
"@m"="#BE32FF"
"@y"="#E3BF65"
"@W"="white"
"@M"="#FF5AFF"
"@b"="#5E5EFF"
"@c"="cyan"
"@R"="#FF5A5A"
"@G"="palegreen"
"@r"="red"
"@Y"="#FFFF5A"
"@w"="#E1E1E1"
"@g"="#2CCE2C"
nil #FF5A5A

somehow colours[1] is showing up as nil when printed using the wildcard, but not when going through the pairs.

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Nick Gammon   Australia  (19,368 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 28 Aug 2007 08:10 AM (UTC)  quote  ]
Message
What pairs is that?

Can you tprint the wildcards?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #2 on Tue 28 Aug 2007 08:57 AM (UTC)  quote  ]
Message

  require "tprint"
  tprint( wildcards )
  tprint( colours )
  tprint( colourcodes )
...


1="1"
2="@R"
0="gain:col1 @R"
1="@G"
2="@W"
"@B"="#78BCFF"
"@C"="#5AFFFF"
"@m"="#BE32FF"
"@y"="#E3BF65"
"@W"="white"
"@M"="#FF5AFF"
"@b"="#5E5EFF"
"@c"="cyan"
"@R"="#FF5A5A"
"@G"="palegreen"
"@r"="red"
"@Y"="#FFFF5A"
"@w"="#E1E1E1"
"@g"="#2CCE2C"
nil #FF5A5A

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #3 on Tue 28 Aug 2007 09:04 AM (UTC)  quote  ]

Amended on Tue 28 Aug 2007 09:05 AM (UTC) by Shaun Biggs

Message
Ok, finally got it figured out... it seems that the only time that Lua doesn't take care of type casting for you is with table keys. this now works:

function ChangeColour( sTrig, sLine, wildcards )
  if colourcodes[ wildcards[2] ] ~= nil then
    colours[ tonumber( wildcards[1] ) ] = wildcards[2]
    ColourNote( colourcodes[ "@W" ],         "", "Colour "..wildcards[1].." set to ",
                colourcodes[ wildcards[2] ], "", wildcards[2] )
  else
    ColourNote( colourcodes[ "@W" ], "", wildcards[2].." is an invalid selection " )
  end
end

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Nick Gammon   Australia  (19,368 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 28 Aug 2007 09:25 PM (UTC)  quote  ]
Message
Tables can be keyed on strings or numbers (amongst other things), so it can't afford to type-cast for you.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


1,686 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]