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
➜ Trigger gives error message "attempting to concatenate nil value". Why?
Trigger gives error message "attempting to concatenate nil value". Why?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Agarwain
(4 posts) Bio
|
Date
| Tue 15 Nov 2011 04:27 AM (UTC) |
Message
| Hello,
I'm trying to do something nifty in Lua, and failing quite miserably. Essentially, I want to create a table of values from a trigger that will examine something called waxlist, and store the wax number, the name of the person who it's of, and the form of the wax. The regexp seems to be fine, because when I finally do type 'waxlist', all hell breaks loose. The trigger:
<triggers>
<trigger
enabled="y"
expand_variables="y"
ignore_case="y"
keep_evaluating="y"
match="^[\d+]?x?\s?"wax(\d+)".*Image: (.*) \((\d+) bondings/?(.*)?\)\.$"
name="waxlist"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>waxlist [item] = { wax_id = "wax" .. tonumber( %2 ), name = "%3", bondings = tonumber( %4 ), form = "%5"}
waxlisted = 1
item = item + 1</send>
</trigger>
</triggers>
And the error:
Run-time error
World: Legends2
Immediate execution
[string "Trigger: waxlist"]:1: attempt to concatenate a nil value
stack traceback:
[string "Trigger: waxlist"]:1: in main chunk
I am thoroughly confused as to why this is. Any help would be greatly appreciated. | Top |
|
Posted by
| Daniel P
USA (97 posts) Bio
|
Date
| Reply #1 on Tue 15 Nov 2011 05:24 AM (UTC) Amended on Tue 15 Nov 2011 05:25 AM (UTC) by Daniel P
|
Message
| If it has this error message, then there's a place where one of your variables or wildcards has just what it says, a nil value, and can't be concatenated with string.
It's just the rule: you can't concatenate a string (this is using the ..) with nothing.
Based on the error line, it looks like this is an issue with something in your waxlist table, specifically with the wax_id = "wax" .. tonumber( %2 ) entry. For some reason or another your wildcard %2 does not have a value and therefore cannot be converted to a number and therefore cannot be concatenated with the string "wax".
This could happen if it was an optional wildcard that wasn't used every time you used the command.
Might want to do some checking such as:
wax_id_num = %2
if wax_id_num == nil
wax_id_num = 0
end -- if
wax_id = "wax" .. tonumber(wax_id_num)
| Top |
|
Posted by
| Agarwain
(4 posts) Bio
|
Date
| Reply #2 on Tue 15 Nov 2011 05:52 AM (UTC) |
Message
| It happens every time the command shows up. A normal iteration looks like:
"wax12345" Image: Agarwain (20 bonds/human).
Am I capturing the %2 (which should be '12345' in the example above) incorrectly then? | Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #3 on Tue 15 Nov 2011 02:13 PM (UTC) |
Message
| What makes you think that 12345 is in %2 instead of %1? |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Agarwain
(4 posts) Bio
|
Date
| Reply #4 on Tue 15 Nov 2011 07:34 PM (UTC) |
Message
| Hmm! i thought [\d+]?x?\s? would count as %1. Guess not. | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #5 on Tue 15 Nov 2011 10:36 PM (UTC) Amended on Tue 15 Nov 2011 10:40 PM (UTC) by Nick Gammon
|
Message
| Only if they are inside (round) brackets are they "captured".
So for example:
%1 would be "foo" and %2 would be "bar". The other words are not captured. This applies whether things are fixed or variable, eg.
|
Regular expressions
- Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
- Also see how Lua string matching patterns work, as documented on the Lua string.find page.
|
Square brackets are used for "sets of things". Are you really looking for a single digit or a plus sign? Or do you mean:
or, to capture it:
That's not the same thing. What you have is the set of digits, plus "+", once. |
- 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.
22,453 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top