Problem with matches[2]

Post Reply
Wennef
Posts: 43
Joined: Sun Apr 11, 2010 3:48 am

Problem with matches[2]

Post by Wennef »

I have this error:
Code: [show] | [select all] lua
TRIGGER:
^You have successfully inscribed the image of the (.+) on your Tarot card.$

ACTION:
expandAlias("pp")
send("ind card")
jestah("Inscribed "..matches[2])

FUNCTION:
function jestah(announce)
cecho("\n<pink>[Jester]: <sky_blue>"..announce)
end

ERROR:
[ERROR:] object:<Card Inscribed> function:<Trigger1621>
         <[string "function Trigger1621()..."]:4: attempt to concatenate a nil value>
here's even the screenshot:
uploadpic.org/v.php?img=S2fzzRP4pH

Frankly, I don't know what's wrong. Halp please?

User avatar
Gilmo
Posts: 25
Joined: Fri Feb 11, 2011 11:43 am

Re: Problem with matches[2]

Post by Gilmo »

What do you see with display(matches)?
I don't know about the trigger match, Ive never inscribed a card, but recreating your script feeding the Trigger copied from your perlregex just works.

Image

Darmir
Posts: 226
Joined: Sun May 01, 2011 6:51 pm
Contact:

Re: Problem with matches[2]

Post by Darmir »

What version of mudlet are you running? The reason I ask is your example should work. You should be able to concatenate right off of matches[2] and I am also not able to do so, which I am running version 2.0+. While testing I did find that when you concatenate the matches inside a function it works, but concatenating two variables and one being matches it breaks, but putting the matches[2] into a variable before concatenating works.

Change it to:
Code: [show] | [select all] lua
local item = matches[2]
expandAlias("pp")
send("ind card")
message = "Inscribed "..item
jestah(message)

User avatar
keneanung
Site Admin
Posts: 94
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Problem with matches[2]

Post by keneanung »

I didn't look very deep into it, but it might be due to expandAlias. There the matches table gets overwritten (as a new regex is being evaluated).

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Problem with matches[2]

Post by Vadi »

Yes, it is. Using:

local value = matches[2]
expandAlias("pp")
send("ind card")
jestah("Inscribed "..value)

Will make it work for you, or...

svo.app("on")
send("ind card")
jestah("Inscribed "..matches[2])

Which is better and more proper

Wennef
Posts: 43
Joined: Sun Apr 11, 2010 3:48 am

Re: Problem with matches[2]

Post by Wennef »

Thanks, will try it.

It works, yay.

What was the problem with mine before it got corrected?

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Problem with matches[2]

Post by Iocun »

The problem was that the matches table gets overwritten any time a trigger or alias fires. Usually that doesn't happen in the middle of a running script, but it will if you explicitly fire an alias or trigger with expandAlias or feedTriggers. So your matches[2], which originally contained the name of your tarot card, became nil after your expandAlias("pp"), since in the "pp" alias, matches[2] is nil.

That's one of the hidden issues with using expandAlias.

Wennef
Posts: 43
Joined: Sun Apr 11, 2010 3:48 am

Re: Problem with matches[2]

Post by Wennef »

Wow. Thanks. Will keep that in mind from now on.

Post Reply