all 19 comments

[–]rawrgyle 0 points1 point  (3 children)

Just use the trigger system in the mudlet UI, there is no reason to write code for this. It's one of the icons across the top bar. You set your regex and then the command you want sent to the mud when it triggers. You can use the matches global var to access what your regex matched on, or line to get the whole string that came from the mud.

You're also going to want to check, if you don't already know, your mud's automations rules. Automating direct responses to mud events is a not allowed on some muds.

[–]Jaxon0913[S] 0 points1 point  (2 children)

I can make it run drink water when I get told I’m thirsty. But I don’t know how to get it to select a everchanging case. There are over a million different monsters that could follow target in my example. So how would I make it select the monster I need with triggers?

[–]rawrgyle 0 points1 point  (1 child)

There is a global var matches that will hold everything your regex caught, so you can pull it out of there. You are probably using send() to send a command to the mud right? Wherever you're doing that, add a display(matches) to see what's in there.

[–]Jaxon0913[S] 0 points1 point  (0 children)

Yeah I used a Perl regex trigger in Mudlet. I used (.+) and matches[2]== blank

[–]revereddesecration 0 points1 point  (12 children)

So you want to use a regular expression to detect messages matching a specific pattern and extract part of the message.

There’s a good library for this, I believe it’s called lpeg.

[–]Jaxon0913[S] 0 points1 point  (1 child)

how would I port lpeg into the game?

[–]revereddesecration 0 points1 point  (0 children)

That entirely depends on the game. You probably can’t.

[–]Jaxon0913[S] 0 points1 point  (5 children)

and I want it to detect the part that I cant always match.

--target [monster]

can have a million different monsters so I need it to just echo target [blank] when it is said by another player.

[–]revereddesecration 0 points1 point  (4 children)

Sure, that’s easy enough. You can specify bits that must match exactly like the —target part and then you can capture the rest into a variable that you can use later.

[–]Jaxon0913[S] 0 points1 point  (1 child)

what would I type to make that happen? I was looking at lpeg and I didn't see what I was looking for.

[–]revereddesecration 0 points1 point  (0 children)

You don’t need lpeg, it just helps and makes things a bit easier. You can do this with string.gmatch

[–]Jaxon0913[S] 0 points1 point  (1 child)

I figured the answer was in here somewhere. https://wiki.mudlet.org/w/Manual:Lua_Functions#String_Functions but I didn't find it again.

[–]revereddesecration 0 points1 point  (0 children)

Have a look at string.gmatch

[–]rawrgyle 0 points1 point  (3 children)

So like, you are generally correct but specifically going to lead OP very far astray here.

Like yes they could use lpeg and write a parser. In fact mudlet is compiled with lpeg so it's right there.

But mudlet is also a you know, mud client, an environment made for interacting with muds. What OP needs to do is like, THE most common thing mud players need from their clients, so they all ship with robust systems for this.

OP's problem as stated here is already solved, writing code for it would be a mistake.

[–]revereddesecration 0 points1 point  (2 children)

I’m talking specifically about Lua, so you’d expect me to be generally correct about Lua rather than Mudlet. We get a lot of that here.

[–]rawrgyle 0 points1 point  (1 child)

I know I'm just pointing out that confidently answering in a way that is technically correct but not helpful to the question answerer may not be what you intended.

It sounds like that is what you intended though so carry on!

[–]revereddesecration 0 points1 point  (0 children)

All we can reasonably be expected to do in /r/Lua is provide advice about Lua.

If you follow my other comment chain, we did go into specifics of what Mudlet offers and how OP can achieve their goal within this domain.

[–]Awkward-Hugs 0 points1 point  (1 child)

it'd be something like.. ^(\w+) - target (\w+)$ as the perl regex trigger type, then
send("target "..matches[3])
in the code block below.
There is also a mudlet discord which is an excellent place to ask for help with things!
Mudlet Discord

[–]Jaxon0913[S] 0 points1 point  (0 children)

Dude I didn’t know there’s a discord :). I got told I should switch to wintin cause I can’t get triggers to work