Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Trigger Capture/String Comparison

Trigger Capture/String Comparison

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Serakyo   (2 posts)  Bio
Date Mon 08 Jun 2009 08:01 AM (UTC)
Message
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!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 08 Jun 2009 08:55 PM (UTC)
Message
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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Serakyo   (2 posts)  Bio
Date Reply #2 on Mon 08 Jun 2009 11:33 PM (UTC)
Message
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!
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,501 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.