Trigger Capture/String Comparison

Posted by Serakyo on Mon 08 Jun 2009 08:01 AM — 3 posts, 14,278 views.

#0
Only just discovered MUSHclient plugins a couple of days ago, soo some of this may be newbie-ish..
Anyways, I'm messing with a plugin and have a problem, specifically with a related trigger and function. The problem is likely in the function, but I'll give all the info here just in case.

First, the text I'm trying to capture, when the command 'gp' is entered, the following comes out:
You have 555 (555) guild points.
* You can use 201 (201) for covert commands.
* You can use 205 (205) for crafts commands.
* All of your guild points can be used for faith commands.
* You can use 269 (269) for fighting commands.
* You can use 139 (139) for magic commands.
* You can use 265 (265) for people commands.
* You can use 265 (265) for adventuring commands.
>

However it can also very easily come out as:
You have 8 (555) guild points.
* You cannot use any guild points for covert commands until you have more than 354.
* You cannot use any guild points for crafts commands until you have more than 350.
* All of your guild points can be used for faith commands.
* You cannot use any guild points for fighting commands until you have more than 286.
* You cannot use any guild points for magic commands until you have more than 416.
* You cannot use any guild points for people commands until you have more than 290.
* You cannot use any guild points for adventuring commands until you have more than 290.
>

Or something between the two. Which is why I was trying to grab the individual lines.
The trigger I was using for that is:
<trigger
enabled="y"
ignore_case="y"
keep_evaluating="y"
match="^(?:> |)*^\* You can use (\d+) ?\((\d+)\) for (.+) commands.$"
regexp="y"
send_to="12"
sequence="2"
variable="test"
>
<send> TypeGPTrigger(%1,%2,%3)</send>
</trigger>

And the function the data is being sent to, is:
function TypeGPTrigger (vGP, vMaxGP, vType)
if (string.find ("covert", [[vType]]) == nil) then mushvar.MaxCoGP = vMaxGP end
if (string.find ("crafts", [[vType]]) == nil) then mushvar.MaxCrGP = vMaxGP end
if (string.find ("faith", [[vType]]) == nil) then mushvar.MaxFaGP = vMaxGP end
if (string.find ("fighting", [[vType]]) == nil) then mushvar.MaxFiGP = vMaxGP end
if (string.find ("magic", [[vType]]) == nil) then mushvar.MaxMaGP = vMaxGP end
if (string.find ("people", [[vType]]) == nil) then mushvar.MaxPeGP = vMaxGP end
if (string.find ("adventuring", [[vType]]) == nil) then mushvar.MaxAdGP = vMaxGP end

CompleteSet()
end -- TypeGPTrigger

With the above, all the variables I'm trying to set, come out as the last one, Adventuring, at 265. I think it's an issue with the string.find not being used correctly or being the wrong command. I had a lot of trouble trying to figure out string comparison for this as I hadn't seen this code before a couple of days ago.

That's everything I think, would appreciate any help I can get, thanks in advance!
Australia Forum Administrator #1
Your string.finds are wrong on a number of levels. Take one for example:


if (string.find ("covert", [[vType]]) == nil) then mushvar.MaxCoGP = vMaxGP end


Now the notation [[vType]] in Lua is just another form of string, so it could be rewritten as:


if (string.find ("covert", "vType") == nil) then mushvar.MaxCoGP = vMaxGP end


So straight away you are not testing the variable vType you are testing the literal "vType" (which will never match).

Next, if string.find returns nil it means it is not found, so you have the sense of the test backwards.

Your next problem is how you are passing the type down to your function. MUSHclient expands out %1, %2, %3 etc. based on the wildcards, so the line:


You can use 201 (201) for covert commands.


... would be passed down (after replacement) as:


 TypeGPTrigger(201,201,covert)


In other words, this sends down the variable covert, not literally "covert". (The variable covert will probably be nil).

See http://mushclient.com/faq point 32 for a bit of a discussion about that aspect.

So, the first change I would make would be to change the way the function is called, like this:


<send> TypeGPTrigger(%1,%2,"%3")</send>


Now at least "covert" will be sent to your function.

Next, change the tests to be more like this:


if vType == "covert" then mushvar.MaxCoGP = vMaxGP
elseif vType == "crafts" then mushvar. MaxCrGP = vMaxGP
elseif vType == "faith" then mushvar. MaxFaGP = vMaxGP
--- and so on
end


I assume the table mushvar exists, or you have another problem again.

#2
Ah! So I had the wrong command in the function AND it was the trigger I made. Have it working and should be able to get all the other bits working now. Thanks for the help!