Prompt trigger

Post Reply
Parnakra
Posts: 35
Joined: Tue Apr 21, 2009 10:48 am

Prompt trigger

Post by Parnakra »

First of all, very nice work on the client. It's blazingly fast and has a lot of potential - if only I could script in Lua.

Anyway, my problem is creating a prompt trigger for Achaea. I've followed the example in the manual, the only difference being I'm using the full prompt, so my pattern is:

Code: Select all

^(\d+)h, (\d+)m, (\d+)e, (\d+)w
I've set the pattern type to substring, saved the trigger and activated it, but it doesn't work. I've tried assigning values to my different variables (health, mana, etc.) through matches[2] to matches[5], but no luck.

Even if I try something simple as echoing matches[1], it does nothing, so I'm guessing the trigger isn't even responding to the line. It's problem an oversight on my part, but any help would be appreciated.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Prompt trigger

Post by Heiko »

You have chosen the wrong pattern type for your pattern. As you are using a Perl regex pattern you must chose the PCRE regex pattern type - not substring - then it'll work.

We'll add more information on the different pattern types to the manual later. The manual is still being compiled. As I'm sure, many users will run into similar problems:

In your example above, your trigger would fire if your prompt in Achaea looked like this ^(\d+)h, (\d+)m, (\d+)e, (\d+)w, but it probably looks like 500h, 500m, 500e, 500w and thus will never fire unless you change the pattern type to regex.

Substring patterns are a literal representation of sequences of letters in a larger sequence of letters, be it a word, a sentence or a paragraph.
If we take this string: "Tom likes Mary, but he doesn't like Mary's sister."
and you'd define this substring pattern: "Mary"
The trigger would fire as soon as the line contains the substring "Mary".
The trigger would match twice on this line if the per /g switch is turned on (= multiple matching of the same trigger on the same line). If this switch is turned off it would only fire once.

Regular expression patterns are a way of expressing more abstract and more complex patterns that go far beyond the literal representation of a substring pattern. In your example (\d*) represents an abstract pattern as it describes a set of possible matches. The trigger would match on any amount of figures. "Tom has 539 books" would match, but "Tom has good books" would match also, because the quantifier * in regex patterns means any amount including nothing of the preceding element which is \d in your example and means any figure (0-9). However, if you want your trigger to match if there is at least one figure in the text you can write: (\d+) as the quantifier + means any amount of number, but at least one.
I'll add more on regular expression in the manual when everything is done. Until then a good reference on the net is: http://www.regular-expressions.info/

If you are using ubuntu or compile your Mudlet binaries from source code you already have Beta-10pre which has graphical user interface colorizer triggers (= highlighter option for triggers). This is the best way to play around with the capabilities of the trigger engine as you can visually see your triggers on the screen as they match.
Beta-10 for Windows will become available this weekend.

Parnakra
Posts: 35
Joined: Tue Apr 21, 2009 10:48 am

Re: Prompt trigger

Post by Parnakra »

Thanks for the help, I knew it had to be something small I overlooked.

Now though, I've run into another problem - and I don't think it deserves a new thread.

I have the following function:

Code: Select all

function checkStats(h, m)
	if (h-cur_health) ~= 0 then
		setBgColor(255,0,0)
		setFgColor(0,0,0)	
		echo(h-cur_health .. "h")
	end
	if m-cur_mana ~= 0 then
		setBgColor(0,0,255)
		setFgColor(0,0,0)
		echo(m-cur_mana .. "m")
	end
	limit = 0.75*health
	echo("\nbefore siphealthif")
	if h <= 0.75*health then
		echo("entered sip if\n")
		sip("health")
	end
	echo("\npast siphealthif")
	cur_health=h
	cur_mana=m
end
This does everything it's supposed to do, up intil the third if. The 'before siphealthif' echo appears, but the one past the expression does not. Any ideas on what's wrong?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Prompt trigger

Post by Heiko »

It's a Lua syntax issue.

Code: Select all

health = 700; 
h = 1
limit = tonumber(0.75*health)
echo("\nbefore siphealthif")
if h <= limit then
	echo("entered sip if\n")
end
echo("\npast siphealthif")
You obviously havent initialized health as a number or m as a number.
To make sure m is interpreted as a number you can use the conversion function tonumber( yourvar )

Post Reply