Substitutions!

Post Reply
Gippal
Posts: 8
Joined: Tue Aug 10, 2010 7:52 pm

Substitutions!

Post by Gippal »

Hey!
I'm new to Mudlet/Lua as a whole, so this could be a multitude of problems, ranging from PCRE, to Lua, to Mudlet in general.

Here is what I'm trying to do!
Change:
Your guardian angel senses Keahi at The Arcanists' Teleportation Chamber, on a health of 4854 and a mana of 3857.

To:
Keahi is at The Arcanists' Teleportation Chamber. Health: 4854. Mana: 3857.


Here's what I tried.
Name: Presences Trigger
Pattern: ^Your guardian angel senses \w at .*\, on a health of \d and a mana of \d\.$
(Perl Regex option in the drop-down menu)
Script:
resetFormat()
selectString("^Your guardian angel senses \w at .*\, on a health of \d and a mana of \d\.$", 1)
replace(matches[2].." is at "..matches[3]..". Health: "..matches[4]..". Mana: "..matches[5]..".")



How did I fail? :D

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

Re: Substitutions!

Post by Iocun »

Ok, first of all \w only matches a -single- letter/digit and \d only matches a -single- digit. For matching one or more of them, you'd use \w+ and \d+. Second, you don't need the \ before the comma. Third, in order to capture your wildcards and use them in the script, you need to put brackets around them. Therefore your pattern should be:

^Your guardian angel senses (\w+) at (.+), on a health of (\d+) and a mana of (\d+)\.$

Then you'll also need to change your selectString() to:
selectString(line, 1)

selectString doesn't work with regular expressions. You have to use literal strings. Line is simply the whole line your trigger matched on. (Alternatively, you could also use matches[1] in this example.)


Last, make sure your screenwidth is set to 0, or the trigger won't match if the message goes over two lines.

Gippal
Posts: 8
Joined: Tue Aug 10, 2010 7:52 pm

Re: Substitutions!

Post by Gippal »

Thanks! That helps clear a lot up. :D
Another question, I was wondering if it was possible to set up different coloring. Such as in Cmud I would do
%1 is at %ansi(high,blue)%2. %ansi(high,green)Health: %3. %ansi(high,blue)Mana: Health: %4.

Is such a thing possible in Mudlet/Lua?

(P.s. Sorry for posting on two forums, a friend told me the other one would be checked more often!)

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

Re: Substitutions!

Post by Vadi »

You could:

replace("")
cecho("<blue>blue <green>green")

and such.

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

Re: Substitutions!

Post by Iocun »

Sure. cecho() allows you to echo something with color tags.

E.g.:

selectString(line,1)
replace("")
cecho("<blue>This is my new <red:blue>replaced <yellow>line.")

<color> makes the color within your foreground color for the next words, <:color> sets the background color. The colors allowed are the ones in Mudlet's color_table. Execute the Mudlet function showColors() to see them all displayed.

In your example, you could do it like:

cecho(matches[2].." is at <DeepSkyBlue>"..matches[3]..". <green>Health: "..matches[4]..". <blue>Mana: "..matches[5]..".")

Or a bit more elegantly (and I believe more efficiently):

cecho(string.format("%s is at %s%s. %sHealth: %s. %sMana: %s.", matches[2], "<magenta>", matches[3], "<green>", matches[3], "<blue>", matches[5]))


P.S. Oops sorry. Posted before I saw Vadi's reply.

Gippal
Posts: 8
Joined: Tue Aug 10, 2010 7:52 pm

Re: Substitutions!

Post by Gippal »

Hey! It worked -well- for a while! Suddenly, today, it was only gagging, with no output.
This is the error I was getting:
object:<Presences Trigger> function:<Trigger42> <edittedmyinfo>/mudlet/LuaGlobal.lua:1127: attempt to call field 'Process' (a nil value.

Trigger:
^Your guardian angel senses (\w+) at (.+), on a health of (\d+) and a mana of (\d+)\.$ (perl regex)
Script:
resetFormat()
selectString(line,1)
replace("")
cecho(matches[2].." is at <yellow>"..matches[3]..". <green>Health: "..matches[4]..". <blue>Mana: "..matches[5]..".")

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: Substitutions!

Post by syrik »

I had a question about something like this! I read the manual, but couldn't find anything on it. I want a trigger that does this: lets say that I am going south, and I come to a door, and when I try to go south again it says "the door seems to be closed" then the trigger would send open door. This would be easy, except that I would have to create a trigger for every door in the mud, so how would I go about doing this so that it would work with more doors? (so basically:

The room of death

my command: east

the hiddenhatch seems to be closed <-- trigger grabs name hiddenhatch opens it, mvs me east, and closes it

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Substitutions!

Post by Denarii »

Gippal wrote:Hey! It worked -well- for a while! Suddenly, today, it was only gagging, with no output.
This is the error I was getting:
object:<Presences Trigger> function:<Trigger42> <edittedmyinfo>/mudlet/LuaGlobal.lua:1127: attempt to call field 'Process' (a nil value.

Trigger:
^Your guardian angel senses (\w+) at (.+), on a health of (\d+) and a mana of (\d+)\.$ (perl regex)
Script:
resetFormat()
selectString(line,1)
replace("")
cecho(matches[2].." is at <yellow>"..matches[3]..". <green>Health: "..matches[4]..". <blue>Mana: "..matches[5]..".")
cecho relies on the Echoes table which contains data and a helper function, have you overwritten it?

Gippal
Posts: 8
Joined: Tue Aug 10, 2010 7:52 pm

Re: Substitutions!

Post by Gippal »

Just looked, and nope! :/
Only tables I have are named general and antitheft.

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Substitutions!

Post by Denarii »

Can you upload your profile? That error really would seem to indicate that the Echoes table has been altered.

Post Reply