Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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
➜ A problem with a table
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Tue 28 Aug 2007 07:15 AM (UTC) |
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 28 Aug 2007 08:10 AM (UTC) |
Message
| What pairs is that?
Can you tprint the wildcards? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #2 on Tue 28 Aug 2007 08:57 AM (UTC) |
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. | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #3 on Tue 28 Aug 2007 09:04 AM (UTC) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #4 on Tue 28 Aug 2007 09:25 PM (UTC) |
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 | 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.
13,214 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top