[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]  Trigger gives error message "attempting to concatenate nil value". Why?

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Trigger gives error message "attempting to concatenate nil value". Why?
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 15 Nov 2011 10:36 PM (UTC)  quote  ]

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:


(foo) dog (bar) cat


%1 would be "foo" and %2 would be "bar". The other words are not captured. This applies whether things are fixed or variable, eg.


([\d+]) dog (.*) cat



Template:regexp 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:


\d+


or, to capture it:


(\d+)


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
[Go to top] top

Posted by Agarwain   (3 posts)  [Biography] bio
Date Tue 15 Nov 2011 07:34 PM (UTC)  quote  ]
Message
Hmm! i thought [\d+]?x?\s? would count as %1. Guess not.
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Tue 15 Nov 2011 02:13 PM (UTC)  quote  ]
Message
What makes you think that 12345 is in %2 instead of %1?

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Agarwain   (3 posts)  [Biography] bio
Date Tue 15 Nov 2011 05:52 AM (UTC)  quote  ]
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?
[Go to top] top

Posted by Daniel P   USA  (77 posts)  [Biography] bio
Date Tue 15 Nov 2011 05:24 AM (UTC)  quote  ]

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)
[Go to top] top

Posted by Agarwain   (3 posts)  [Biography] bio
Date Tue 15 Nov 2011 04:27 AM (UTC)  quote  ]
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?&quot;wax(\d+)&quot;.*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.
[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,385 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]