What's the limit on the match text string?

Posted by WillFa on Wed 20 Aug 2008 02:43 AM — 4 posts, 11,035 views.

USA #0
Just wondering if there will be some point where a trigger becomes too long and needs to become less complicated.

i.e. my previous stupid question is used to build this match pattern:

^You (?P<verb>trounced|pummeled|smashed|pulverized|struck|hit|massacred|utterly annihilated) (?P<critter>.*?) ?(?P<predicate>up and down|into small fragments|with a bone crushing sound|with a powerful attack|a mighty blow|very hard|into tiny fragments|)?\.$

and add to it when I get a new damage emote.
Is there a point where I'll have to make a second trigger?
Australia Forum Administrator #1
I think this came up a while ago - someone had something like 1000 alternatives which at the time caused the PCRE to fail, however that should work now.

You probably should, for efficiency reasons, make a simple trigger like:

<verb> <mob> <predicate>

and then do a table lookup in Lua for the verb and mob. A table lookup will probably be faster than making the regexp handler iterate linearly over many alternatives.
USA #2
Hmm. The main purpose of this trigger (though it will have others) is to grab the mob name. On the mud I play, room description isn't necessarily the target (i.e. "A cloaked figure" is "Vampire Spy" when you kill it). So I do want to pull it from the damage emote.
Also there are adverbs too.

(snipped thinking out loud stuff)

It's a good idea, does the above give you any other thoughts?
Amended on Thu 21 Aug 2008 02:48 AM by WillFa
USA #3
Here's what I came up with... feedback is appreciated.


assert(loadstring(var.DamageVerbTbl or [[DamageVerbTbl = {
tickled = " in the stomach%.",
grazed = "%.",
hit = {" very hard%.", " hard%.", "%."},
struck = " a mighty blow%.",
smashed  = " with a bone crushing sound%.",
pulverized = " with a powerful attack%.",
trounced = " up and down%.",
pummeled = " into small fragments%.",
["utterly annihilated"] = "%.",
massacred = " into tiny fragments.",
["completely devastated"] = " with awesome force%.",
destroyed = ".",
["absolutely massacred"]  = "%.",
} ]] ))()

function GetCritterName (t,l,w)
--	^You (?P<DamageVerb>@!DamageVerb) (?P<EmoteRemainder>.+)$
	local workString = w.EmoteRemainder
	if type(DamageVerbTbl[w.DamageVerb]) == "table" then
		for k,_ in ipairs(DamageVerbTbl[w.DamageVerb]) do
			workString = workString:gsub(DamageVerbTbl[w.DamageVerb][k], "")
		end
	else
		workString = workString:gsub(DamageVerbTbl[w.DamageVerb], "")
	end	
	if workString == w.EmoteRemainder then
		ParseNewDamageEmote(nil,nil, {NewVerb = w.DamageVerb, NewPredicate = w.EmoteRemainder:gsub(var.Enemy, "")})
	end
	if not t then	
		return workString
	else
		var.Enemy = workString:gsub("(%p)","%%%1")
	end
end

function ParseNewDamageEmote (t,l,w)
--	^You (?P<NewVerb>.+) @!Enemy(?P<NewPredicate>.+)$
	local verb, pred = w.NewVerb, w.NewPredicate:gsub("(%p)","%%%1")
	if not DamageVerbTbl[verb] then
		DamageVerbTbl[verb] = pred
	else
		if type(DamageVerbTbl) == "string" then --need to convert to a table
			local tmp = DamageVerbTbl[verb]
			DamageVerbTbl[verb] = {DamageVerbTbl[verb]}
		end
		local isSubString = false
		for k,v in ipairs(DamageVerbTbl[verb]) do
			if v:match(pred) then -- see if new predicate is a substring. i.e. old = " very hard." new = " hard."
				isSubString = k
				break
			end
		end
		if isSubString then
			table.insert (DamageVerbTbl[verb], k+1, pred)
		else
			DamageVerbTbl[verb][#DamageVerbTbl[verb]] = pred
		end
	end
	local varDamageVerb = ""
	for k,_ in pairs(DamageVerbTbl) do
		varDamageVerb = varDamageVerb .. k .. "|"
	end
	var.DamageVerb = varDamageVerb:sub(1,-2)
	var.DamageVerbTbl = serialize.save("DamageVerbTbl")
end