[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  capturing a full string w/ wild cards
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

capturing a full string w/ wild cards

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


Posted by Silencher   (54 posts)  [Biography] bio
Date Thu 26 Feb 2015 08:50 AM (UTC)
Message
<triggers>
<trigger
group="TargetTrigger"
match="* attacks you *"
sequence="100"
>
<send>attacker = "%1"
SetVariable("Target", attacker)
testTarget = GetVariable("Target")
Note("Target is " .. testTarget)
</send>
</trigger>
</triggers>



Above is a trigger I have. The goal is to pull everything from the first * and store it into a string so I can use another alias to 'attack target'.

However, in the mud I'm playing, the info in that first * could range from a single name like 'Mike' to a short description, like 'a fluffy white poodle'.

I can't seem to get it to work. The alias I have is simple enough, and if I use a string, rather than 'testTarget', it fires correctly. The only thing I can think is that the first wildcard is not correctly being saved to the testTarget / Attacker variables.

Basically, this is just a way for me to quickly respond to aggressive mobs and/or PVP situations. Can anyone tell me what I'm missing?
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #1 on Thu 26 Feb 2015 10:22 AM (UTC)
Message
The problem is that your trigger is too greedy in what it captures. Short descriptions are, frankly, horrible for setting combat triggers against because they usually contain a bunch of extra 'fluff' that isn't a valid name for the mob you're fighting. Your fluffy white poodle for instance might have name keywords of dog and poodle but not fluffy or white and certainly won't have a as a recognized keyword. When your trigger attempts to feed 'a fluffy white poodle' as your target the server has no idea what you're talking about because you didn't give it a recognizable target.

If you intend to continue with this plan to respond to being attacked, you're going to need to build a database of descriptions and their corresponding keywords to feed your target variables or you're going to continue to run into issues with things like fluffy white poodles and lazy gate guards.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Silencher   (54 posts)  [Biography] bio
Date Reply #2 on Fri 27 Feb 2015 03:09 AM (UTC)
Message
The thing is my alias would be mostly just for PCs, but I need the trigger to work for everything. And right now it doesn't seem to take the string and insert it into the variable.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #3 on Fri 27 Feb 2015 04:11 AM (UTC)

Amended on Fri 27 Feb 2015 04:13 AM (UTC) by Meerclar

Message
If it works for any mobs, it's working for all of them. As I said before, the problem is that you're using the mob short descriptions rather than picking out functional keywords for your trigger. Players (probably) won't ever present such a problem because their only keyword should be their name. Also, if you're only trying to use this in response to aggressive mobs, you might be able to use mud aliases to get around even needing to pass names/ short descriptions to your alias at all.

Might be easier for us to verify with some actual output from your mud as well.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Lua_Newbie   (25 posts)  [Biography] bio
Date Reply #4 on Fri 27 Feb 2015 10:56 AM (UTC)

Amended on Fri 27 Feb 2015 11:12 AM (UTC) by Lua_Newbie

Message
There's a much easier way of doing this I believe. At the moment you have this:

Quote:


<triggers>
<trigger
group="TargetTrigger"
match="* attacks you *"
sequence="100"
>
<send>attacker = "%1"
SetVariable("TARGET", attacker)
testTarget = GetVariable("TARGET")
Note("Target is " .. testTarget)
</send>
</trigger>
</triggers>



And I think you need something like this:

Quote:


<triggers>
<trigger
group="TargetTrigger"
match="* attacks you *"
sequence="100"
>
SetVariable(target)
target = %1
Note("Target is : ", target)
</trigger>
</triggers>



In your example you have 2 variables doing the same thing: "TARGET" and "testtarget"

In my example it is simplified to one.. "target"

I could be wrong with this but it's my best shot, let us know how it goes :)

- Lunk (of Aardwolf)
[Go to top] top

Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 28 Feb 2015 03:51 AM (UTC)
Message
Silencher said:

I can't seem to get it to work. The alias I have is simple enough, and if I use a string, rather than 'testTarget', it fires correctly. The only thing I can think is that the first wildcard is not correctly being saved to the testTarget / Attacker variables.



What do you mean "if I use a string"? Can you post example output?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by LBot   (1 post)  [Biography] bio
Date Reply #6 on Fri 03 Apr 2015 05:30 AM (UTC)
Message
I think you'll find that replacing

testTarget = GetVariable("TARGET")
with
testTarget = tostring(GetVariable("TARGET"))

will solve your problem here.

Without the tostring() the interpreter appears to that the value of the variable as another variable name, rather than a string. At least, that's been my experience so far.
[Go to top] top

Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 03 Apr 2015 06:59 AM (UTC)
Message
GetVariable always returns strings (or nil if the variable does not exist).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


4,672 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]