Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ What's the limit on the match text string?

What's the limit on the match text string?

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


Posted by WillFa   USA  (525 posts)  Bio
Date Wed 20 Aug 2008 02:43 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 20 Aug 2008 03:38 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #2 on Wed 20 Aug 2008 04:42 AM (UTC)

Amended on Thu 21 Aug 2008 02:48 AM (UTC) by WillFa

Message
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?
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #3 on Thu 21 Aug 2008 02:48 AM (UTC)
Message
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
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.


10,789 views.

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

Go to topic:           Search the forum


[Go to top] top

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