Newbie Multi-Line Trigger

User avatar
Zaphob
Posts: 180
Joined: Wed May 09, 2012 8:07 am
Location: mg.mud.de

Re: Newbie Multi-Line Trigger

Post by Zaphob »

While I was using the above trigger for many years now to great success, I recently noticed it would fail with single lines.

There is a detailed description of the perceived problems and tested solutions in the github issue:
https://github.com/Mudlet/Mudlet/issues/4910

Afterwards, Edru was kind enough to code a new set of triggers to work with single and multiple lined texts:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
	<TriggerPackage>
		<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
			<name>Kerbholz start</name>
			<script>KerbholzText = ""
properEnd = nil</script>
			<triggerType>0</triggerType>
			<conditonLineDelta>0</conditonLineDelta>
			<mStayOpen>50</mStayOpen>
			<mCommand></mCommand>
			<packageName></packageName>
			<mFgColor>#ff0000</mFgColor>
			<mBgColor>#ffff00</mBgColor>
			<mSoundFile></mSoundFile>
			<colorTriggerFgColor>#000000</colorTriggerFgColor>
			<colorTriggerBgColor>#000000</colorTriggerBgColor>
			<regexCodeList>
				<string>Du richtest Dein Kerbholz auf</string>
			</regexCodeList>
			<regexCodePropertyList>
				<integer>2</integer>
			</regexCodePropertyList>
			<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
				<name>gatherContent</name>
				<script>KerbholzText = KerbholzText .. matches[1]</script>
				<triggerType>0</triggerType>
				<conditonLineDelta>0</conditonLineDelta>
				<mStayOpen>0</mStayOpen>
				<mCommand></mCommand>
				<packageName></packageName>
				<mFgColor>#ff0000</mFgColor>
				<mBgColor>#ffff00</mBgColor>
				<mSoundFile></mSoundFile>
				<colorTriggerFgColor>#000000</colorTriggerFgColor>
				<colorTriggerBgColor>#000000</colorTriggerBgColor>
				<regexCodeList>
					<string>(Du richtest Dein Kerbholz auf )?([^.]+)</string>
				</regexCodeList>
				<regexCodePropertyList>
					<integer>1</integer>
				</regexCodePropertyList>
			</Trigger>
			<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
				<name>Kerbholz proper end</name>
				<script>setTriggerStayOpen( "Kerbholz start", 0 )
KerbholzText = KerbholzText:gsub("\n", "")
echo("\nSucess\n")
echo("Trigger content is ")
echo(KerbholzText)
echo("\n")
properEnd = true
</script>
				<triggerType>0</triggerType>
				<conditonLineDelta>0</conditonLineDelta>
				<mStayOpen>0</mStayOpen>
				<mCommand></mCommand>
				<packageName></packageName>
				<mFgColor>#ff0000</mFgColor>
				<mBgColor>#ffff00</mBgColor>
				<mSoundFile></mSoundFile>
				<colorTriggerFgColor>#000000</colorTriggerFgColor>
				<colorTriggerBgColor>#000000</colorTriggerBgColor>
				<regexCodeList>
					<string>.*es passiert nichts\.$</string>
				</regexCodeList>
				<regexCodePropertyList>
					<integer>1</integer>
				</regexCodePropertyList>
			</Trigger>
			<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
				<name>Kerbolz different end</name>
				<script>if not properEnd then
  echo("\nTrigger endend differently. Clearing Trigger content\n")
  KerbholzText = nil
  setTriggerStayOpen( "Kerbholz start", 0 )
end</script>
				<triggerType>0</triggerType>
				<conditonLineDelta>0</conditonLineDelta>
				<mStayOpen>0</mStayOpen>
				<mCommand></mCommand>
				<packageName></packageName>
				<mFgColor>#ff0000</mFgColor>
				<mBgColor>#ffff00</mBgColor>
				<mSoundFile></mSoundFile>
				<colorTriggerFgColor>#000000</colorTriggerFgColor>
				<colorTriggerBgColor>#000000</colorTriggerBgColor>
				<regexCodeList>
					<string>\.$</string>
				</regexCodeList>
				<regexCodePropertyList>
					<integer>1</integer>
				</regexCodePropertyList>
			</Trigger>
		</Trigger>
	</TriggerPackage>
</MudletPackage>
(Which was still a bit rough on the edges, for example as this very text seems to end in full stop followed by another space character, etc.) Plus:
Edru wrote: Maybe it would be smarter to check if the end is proper differently by getting rid of the Kerbholz proper end trigger and change the different end pattern to just a

Code: Select all

\.
and add this in that triggers code section

Code: Select all

setTriggerStayOpen( "Kerbholz start", 0 )
KerbholzText = KerbholzText:gsub("\n", "")

if KerbholzText:match("es passiert nichts$") then
    echo("\nSuccess\n")
    echo("Trigger content is ")
    cecho("<yellow>"..KerbholzText)
    echo("\n")
else
    KerbholzText = nil
    echo("\nTrigger endend differently. Clearing Trigger content\n")
end
like this it will also match if the trigger with

Code: Select all

nichts.
in new line
The end goal should be a set of generic trigger templates that can be adjusted easily and used for many different texts quickly.

Maybe put a global TRIGGER table with each having a few small functions like match_start and match_end plus name, length, captured text, etc.

Post Reply